using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.IO;
using System.Data.SqlClient;
using AjaxControlToolkit;
using MBLocale;

/// <summary>
/// Summary description for PageCommonFunctions
/// </summary>
public class PageCommonFunctions
{
    HtmlForm frmObjTotals = null;
    string ownerid = "owner_id";
    HtmlTable Htmltable = new HtmlTable();
    public PageCommonFunctions()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public PageCommonFunctions(HtmlForm htmlform)
    {
        frmObjTotals = htmlform;
    }

    public bool IsParentPageKeyControl(string strCtrlColumn, DataTable dtaPage, DataTable dtaPageKeys, int intPageSeq)
    {
        bool blnStatus = false;
        string strPageKey = "";
        string strPageId = "";
        if (intPageSeq > 0)
        {
            strPageId = dtaPage.Rows[0]["page_id"].ToString();
            DataRow[] droKeys = dtaPageKeys.Select("page_id='" + strPageId + "'");//, "page_key_seq");
            for (int j = 0; j < droKeys.Length; j++)
            {
                strPageKey = droKeys[j]["page_key"].ToString();
                if (strPageKey.ToLower() == strCtrlColumn.ToLower())
                {
                    blnStatus = true;
                }
            }
        }
        return blnStatus;
    }

    public string FindInputValue(DataSet dsePageInputInfo, string strPageId, string strCtrlColumnId, DataTable dtaPageCtrl)
    {
        string strRet = "";
        strRet = FindInputValue(dsePageInputInfo.Tables[strPageId], strPageId, strCtrlColumnId, dtaPageCtrl);
        return strRet;
    }

    public string FindInputValue(DataTable dtaPageInputInfo, string strPageId, string strCtrlColumnId, DataTable dtaPageCtrl)
    {
        string strRet = "";
        string strCtrlId = "";
        DataRow[] droObj = dtaPageCtrl.Select("page_id='" + strPageId + "' and control_attrib_id='" + strCtrlColumnId + "'");
        if (droObj.Length > 0)
        {
            strCtrlId = droObj[0]["control_attrib_id"].ToString();/////strCtrlId = droObj[0]["control_id"].ToString();
            strRet = dtaPageInputInfo.Rows[0][strCtrlId].ToString();
        }
        return strRet;
    }

    private bool getMasterValues(string ActualControlId, DataTable dtPageKeys, DropDownList DDL, string DefaultValue)
    {
        bool bRet = false;

        DataRow[] drr = dtPageKeys.Select("attrib_id='" + ActualControlId + "'");
        if (drr.Length > 0)
        {
            MasterDetail MD = new MasterDetail();
            MD.FillMasterValues(ActualControlId, drr[0], DDL, DefaultValue);
            bRet = true;
        }
        return bRet;
    }
    private bool getMasterValues(string ActualControlId, DataTable dtPageKeys, TextBox txtobj,HiddenField hfobj, string DefaultValue)
    {
        bool bRet = false;

        DataRow[] drr = dtPageKeys.Select("attrib_id='" + ActualControlId + "'");
        if (drr.Length > 0)
        {
            MasterDetail MD = new MasterDetail();
            //MD.FillMasterValues(ActualControlId, drr[0], DDL, DefaultValue);
            MD.FillMasterValues(ActualControlId, drr[0], txtobj,hfobj, DefaultValue);
            bRet = true;
        }
        return bRet;
    }

    //private bool CreateMasterDetailControl(ref ArrayList arlHtmlCells, string ActualControlId, string ControlId, string ControlDesc,string strBr, string controlWidth, bool EveryRowCaption, string strPageView, DataTable dtPageKeys, string DefaultValue)
    //{
    //    //ArrayList arlHtmlCells = new ArrayList();
    //    bool bReturn = false;
    //    Label lblObj = new Label();
    //    HtmlTableCell htc = new HtmlTableCell();
    //    htc.VAlign = "middle";
    //    htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
    //    lblObj.ID = "lb_" + ControlId;
    //    lblObj.Text = ControlDesc + strBr;
    //    setLabelFont(ref lblObj);
    //    //DropDownList DDL = new DropDownList();
    //    //DDL.ID = ControlId;
        
    //    //replace drop downs with textboxes
    //    TextBox txtobj = new TextBox();
    //    txtobj.ID = "txt_" + ControlId;
    //    HiddenField hfobj = new HiddenField();
    //    hfobj.ID = ControlId;
    //    txtobj.CssClass = "controlFont";
    //    //

    //    //DDL.CssClass = "controlFont"; // Added by srivatsan on Feb-20-2009
    //    if (controlWidth != "")
    //    {
    //        //DDL.Width = Unit.Pixel(Convert.ToInt32(controlWidth));
    //        txtobj.Width = Unit.Pixel(Convert.ToInt32(controlWidth));
    //    }
    //    if (EveryRowCaption)
    //    {
    //        htc.Controls.Add(lblObj);
    //    }

    //    //if (getMasterValues(ActualControlId, dtPageKeys, DDL, DefaultValue))
    //    if(getMasterValues(ActualControlId,dtPageKeys,txtobj,hfobj,DefaultValue))
    //    {
    //        bReturn = true;
    //        if (strPageView == "2")
    //        {
    //            arlHtmlCells.Add(htc);
    //            htc = new HtmlTableCell();
    //        }

    //        if (HttpContext.Current.Request.QueryString["Vmode"] != null)
    //        {
    //            txtobj.Enabled = false;
    //        }

    //        //htc.Controls.Add(DDL);
    //        htc.Controls.Add(txtobj);
    //        htc.Controls.Add(hfobj);
    //        //AddSearchLink(ref htc, ActualControlId, hfobj.ID, txtobj.ID, "");

    //        string strTableName = "";
    //        string bindfield = "";
    //        if (dtPageKeys != null)
    //        {
    //            if (dtPageKeys.Rows.Count > 0)
    //                            {
    //                                HDDatabase HDD =new HDDatabase();

    //                                DataRow[] drrmasterlink = dtPageKeys.Select("attrib_id = '" + ActualControlId + "'");
    //                string masterobj = "";
    //                if (drrmasterlink.Length > 0)
    //                {
    //                    masterobj = drrmasterlink[0]["master_obj"].ToString();
    //                    bindfield = drrmasterlink[0]["display_att"].ToString();
    //                }
    //                                //string masterobj = dtPageKeys.Rows[0]["master_obj"].ToString();
    //                                //bindfield = dtPageKeys.Rows[0]["display_att"].ToString();
    //                                strTableName = HDD.GetColumnValue("sy_obj", "object_table", "object_id='" + masterobj + "'");
    //                                    HDD = null;
    //                            }
    //                        }
    //                        if (HttpContext.Current.Request.QueryString["VMode"] == null)
    //                        {
    //                            if (bindfield.Trim() != "")
    //                            {
    //                                if (strTableName.Trim() != "")
    //                                {
    //                                    AddSearchLinkForMasterDetail(ref htc, ActualControlId, hfobj.ID, txtobj.ID, "", bindfield, strTableName);
    //                                }
    //                            }
    //                        }
    //        //addMandatoryValidator(ref htc, DDL);
    //        addMandatoryValidator(ref htc, txtobj);
    //        arlHtmlCells.Add(htc);
    //    }
    //    else
    //        bReturn = false;
        
    //    //return arlHtmlCells;
    //    return bReturn;
    //}


    private bool CreateMasterDetailControl(ref ArrayList arlHtmlCells, string ActualControlId, string ControlId, string ControlDesc, string strBr, string controlWidth, bool EveryRowCaption, string strPageView, DataTable dtPageKeys, string DefaultValue,DataSet dsInput)
    {
        //ArrayList arlHtmlCells = new ArrayList();
        bool bReturn = false;
        Label lblObj = new Label();
        HtmlTableCell htc = new HtmlTableCell();
        htc.VAlign = "middle";
        htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
        lblObj.ID = "lb_" + ControlId;
        lblObj.Text = ControlDesc + strBr;
        setLabelFont(ref lblObj);
        if (dsInput != null)
        {
            lblObj.Visible = false;
        }
        //DropDownList DDL = new DropDownList();
        //DDL.ID = ControlId;

        //replace drop downs with textboxes
        TextBox txtobj = new TextBox();
        txtobj.ID = "txt_" + ControlId;
        HiddenField hfobj = new HiddenField();
        hfobj.ID = ControlId;
        txtobj.CssClass = "controlFont";
        //
        if (dsInput != null)
        {
            txtobj.Visible = false;
            if (HttpContext.Current.Request.QueryString["PK"] != null)
            {
                hfobj.Value = HttpContext.Current.Request.QueryString["PK"].ToString();
            }
        }
        //

        //DDL.CssClass = "controlFont"; // Added by srivatsan on Feb-20-2009
        if (controlWidth != "")
        {
            //DDL.Width = Unit.Pixel(Convert.ToInt32(controlWidth));
            txtobj.Width = Unit.Pixel(Convert.ToInt32(controlWidth));
        }
        if (EveryRowCaption)
        {
            htc.Controls.Add(lblObj);
        }

        //if (getMasterValues(ActualControlId, dtPageKeys, DDL, DefaultValue))
        if (getMasterValues(ActualControlId, dtPageKeys, txtobj, hfobj, DefaultValue))
        {
            bReturn = true;
            if (strPageView == "2")
            {
                arlHtmlCells.Add(htc);
                htc = new HtmlTableCell();
            }

            if (HttpContext.Current.Request.QueryString["Vmode"] != null)
            {
                txtobj.Enabled = false;
            }

            //htc.Controls.Add(DDL);
            htc.Controls.Add(txtobj);
            htc.Controls.Add(hfobj);
            //AddSearchLink(ref htc, ActualControlId, hfobj.ID, txtobj.ID, "");

            string strTableName = "";
            string bindfield = "";
            if (dtPageKeys != null)
            {
                if (dtPageKeys.Rows.Count > 0)
                {
                    HDDatabase HDD = new HDDatabase();

                    DataRow[] drrmasterlink = dtPageKeys.Select("attrib_id = '" + ActualControlId + "'");
                    string masterobj = "";
                    if (drrmasterlink.Length > 0)
                    {
                        masterobj = drrmasterlink[0]["master_obj"].ToString();
                        bindfield = drrmasterlink[0]["display_att"].ToString();
                    }
                    //string masterobj = dtPageKeys.Rows[0]["master_obj"].ToString();
                    //bindfield = dtPageKeys.Rows[0]["display_att"].ToString();
                    strTableName = HDD.GetColumnValue("sy_obj", "object_table", "object_id='" + masterobj + "'");
                    HDD = null;
                }
            }
            if (HttpContext.Current.Request.QueryString["VMode"] == null)
            {
                if (bindfield.Trim() != "")
                {
                    if (strTableName.Trim() != "")
                    {
                        if (dsInput == null) // Check if not transaction document page
                        {
                            AddSearchLinkForMasterDetail(ref htc, ActualControlId, hfobj.ID, txtobj.ID, "", bindfield, strTableName);
                        }
                    }
                }
            }
            //addMandatoryValidator(ref htc, DDL);
            if (dsInput == null) // check if not transaction document page
            {
                addMandatoryValidator(ref htc, txtobj);
            }
            arlHtmlCells.Add(htc);
        }
        else
            bReturn = false;

        //return arlHtmlCells;
        return bReturn;
    }



    //public ArrayList ControlInit(HtmlTableCell htc, int intCurrentRow, String strPageView, string strCtrlId, string strCtrlDesc,
    //     string strBindRowID, string strCtrlHtml, ArrayList arlHtmlCells, bool blnSeqControl, BindControl BC, string strDefaultVal,
    //     bool blnCaption, string strActualCtrlId, string strCtrlWidth, string ObjId, string IsKey,string IsPrimary,
    //    bool IsMutipleRecordPage, bool IsEdit, string Attrib_Size, DataRow droTemp, DataTable dtPageKeys,string IsRelationalField,string tooltip,string inputMask)
    //{
    //    string strBr = ""; DataTable dtBind = new DataTable();
    //    System.Drawing.Color cKey = System.Drawing.Color.Gray;
    //    if (strPageView == "1")
    //    {
    //        strBr = "<br>";
    //    }

    //    if (strDefaultVal.StartsWith("{!") && strDefaultVal.EndsWith("}"))
    //    {
    //        //strDefaultVal = strDefaultVal.Substring(2, strDefaultVal.Length - 2 - 1);
    //        Hashtable hsSysVar = (Hashtable)HttpContext.Current.Session["SysVar"];
    //        if (hsSysVar.Contains(strDefaultVal))
    //            strDefaultVal = hsSysVar[strDefaultVal].ToString();
    //        /*if (GlobalValues.hsSysVar.Contains(strDefaultVal))
    //            strDefaultVal = GlobalValues.hsSysVar[strDefaultVal].ToString();*/
    //    }
    //    else if (strDefaultVal.StartsWith("{@") && strDefaultVal.EndsWith("}"))
    //    {
    //        security hds = new security();
    //        Hashtable hsAppVar = new Hashtable();
    //        hds.loadAppVariables(ref hsAppVar);
    //        hds = null;
    //        if (hsAppVar.Contains(strDefaultVal))
    //            strDefaultVal = hsAppVar[strDefaultVal].ToString();
    //        //if (GlobalValues.hsAppVar.Contains(strDefaultVal))
    //        //    strDefaultVal = GlobalValues.hsAppVar[strDefaultVal].ToString();
    //    }
    //    else if (strDefaultVal == "CurrentDate()")
    //    {
    //        strDefaultVal = DateTime.Now.ToShortDateString();
    //    }

    //    if (!CreateMasterDetailControl(ref arlHtmlCells, strActualCtrlId, strCtrlId, strCtrlDesc, strBr, strCtrlWidth, blnCaption, strPageView, dtPageKeys, strDefaultVal))
    //    //if (arlHtmlCells.Count == 0)
    //    {
    //        Label lblObj = new Label();

    //        switch (strCtrlHtml.ToUpper())
    //        {
    //            case "TB":
    //                security sec = new security();
    //                bool change_owner = false;
    //                if (strActualCtrlId.ToLower() == ownerid)
    //                {
    //                    change_owner = sec.getRightsForMRUObjects(HttpContext.Current.Request.QueryString["pgs_id"].ToString(), "change_owner");
    //                }
                    
    //                sec = null;

    //                htc = new HtmlTableCell();
    //                //htc.VAlign = "middle"; // commented by srivatsan
    //                htc.VAlign = "top";
    //                htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
    //                //htc.Controls.Add(new LiteralControl(strCtrlDesc + strBr));
    //                lblObj.ID = "lb_" + strCtrlId;
    //                lblObj.Text = strCtrlDesc + strBr;
    //                setLabelFont(ref lblObj);
    //                ////lblObj.Width = intLabelSize;
    //                TextBox txtObj = new TextBox();
    //                txtObj.ID = strCtrlId;
    //                if (strBindRowID != "") //Srivatsan on July 16 2009
    //                {
    //                    txtObj.ID = "txt_" + strCtrlId;
    //                }
    //                txtObj.Text = strDefaultVal;
    //                if (tooltip != "")
    //                    txtObj.ToolTip = tooltip;//implemented by sanal on 11 Mar 2008
    //                if (strCtrlWidth != "")
    //                {
    //                    txtObj.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
    //                }
    //                if (strActualCtrlId == GlobalValues.CreatedDate)
    //                {
    //                    txtObj.Text = DateTime.Now.ToString();
    //                    txtObj.Enabled = false;
    //                }
    //                else if (strActualCtrlId == GlobalValues.ModifiedDate)
    //                {
    //                    txtObj.Enabled = false;
    //                }

    //                if (Attrib_Size != "")
    //                    txtObj.MaxLength = Convert.ToInt32(Attrib_Size);

    //                if (blnSeqControl)
    //                {
    //                    txtObj.Text = intCurrentRow.ToString();
    //                }
    //                //txtObj.Attributes.Add("style","text-align:right");
    //                //if (droTemp["control_attrib_type"].ToString() == "NU" || droTemp["control_attrib_type"].ToString() == "DC" || droTemp["control_attrib_type"].ToString() == "CU")
    //                //    txtObj.Attributes["dir"] = "rtl";

    //                if (!IsEdit) txtObj.Enabled = false;
    //                if (strActualCtrlId.ToLower() == ownerid)
    //                {
    //                    if (!change_owner)
    //                    {
    //                        txtObj.Enabled = false;
    //                    }
    //                }
    //                if (blnCaption)
    //                {
    //                    htc.Controls.Add(lblObj);
    //                }
    //                if (strPageView == "2")
    //                {
    //                    arlHtmlCells.Add(htc);
    //                    htc = new HtmlTableCell();
    //                }
    //                txtObj.CssClass = "controlFont controlWidth";
    //                htc.Controls.Add(txtObj);
    //                if (strBindRowID != "")
    //                {
    //                    HiddenField hf = new HiddenField();
    //                    hf.ID = strCtrlId;
    //                    SetDefaultValueForOwnerID(ref txtObj, ref hf, strActualCtrlId);
    //                    htc.Controls.Add(hf);
    //                }
    //               // txtObj.Width = Unit.Pixel(225); //srivatsan
                   
    //                //loadDateTimeScript(droTemp, ref htc, txtObj.ID,ref DateTimestring);
    //                addDateIfDateTime(droTemp, ref htc, txtObj.ID);
    //                ///
    //                if (strBindRowID != "")//sanal
    //                {
    //                    //htc.Controls.Add(getBindDIV(txtObj.ID, strBindRowID, null,true)); // Commented by srivatsan on July 16 2009
    //                    if (!isViewMode())
    //                    {
    //                        if (strActualCtrlId.ToLower() == ownerid)
    //                        {
    //                            if (change_owner)
    //                            {
    //                                AddSearchLink(ref htc, strActualCtrlId, strCtrlId, txtObj.ID, strBindRowID); // added by srivatsan on july 15 2009
    //                            }
    //                        }
    //                        else
    //                        {
    //                            AddSearchLink(ref htc, strActualCtrlId, strCtrlId, txtObj.ID, strBindRowID); // added by srivatsan on july 15 2009}
    //                        }
    //                    }
    //                    if (strActualCtrlId != ownerid)
    //                    {
    //                        htc.Controls.Add(getBindNewLink(strBindRowID, null));
    //                    }
    //                    htc.Style.Add("white-space", "nowrap");

                        
    //                }
                    
    //                if (IsKey == "true")
    //                {
    //                    txtObj.BorderColor = cKey;
    //                    if (HttpContext.Current.Request.QueryString.Get("CPY") == null && HttpContext.Current.Request.QueryString.Get("PK") != null && !IsMutipleRecordPage)
    //                    {
    //                        txtObj.Enabled = false;
    //                    }
    //                    /*Label lblKey = new Label();
    //                    lblKey.ForeColor = System.Drawing.Color.Red;
    //                    lblKey.Text = "*";
    //                    htc.Controls.Add(lblKey);*/
    //                    //addMandatoryValidator(ref htc, txtObj);
    //                }
    //                if (IsPrimary == "true") addMandatoryValidator(ref htc, txtObj);
    //                if (inputMask != "") processInputMask(ref htc, txtObj,inputMask);
    //                htc.VAlign = "top"; // Added bysrivatsan on mar 19 2009
    //                arlHtmlCells.Add(htc);
    //                break;
    //            case "TA":
    //                htc = new HtmlTableCell();
    //               // htc.VAlign = "middle";  // Commented by srivatsan on Mar 19 2009
    //                htc.VAlign = "top";
    //                htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
    //                //htc.Controls.Add(new LiteralControl(strCtrlDesc + strBr));
    //                lblObj.ID = "lb_" + strCtrlId;
    //                lblObj.Text = strCtrlDesc + strBr;
    //                setLabelFont(ref lblObj);
    //                ////lblObj.Width = intLabelSize;
    //                txtObj = new TextBox();
    //                txtObj.TextMode = TextBoxMode.MultiLine;
    //                txtObj.Rows = 4;
    //                txtObj.ID = strCtrlId;
    //                txtObj.Text = strDefaultVal;
    //                if (tooltip != "")
    //                    txtObj.ToolTip = tooltip;//implemented by sanal on 11 Mar 2008
    //                if (strCtrlWidth != "")
    //                {
    //                    txtObj.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
    //                }
    //                if (strActualCtrlId == GlobalValues.CreatedDate)
    //                {
    //                    txtObj.Text = DateTime.Now.ToString();
    //                    txtObj.Enabled = false;
    //                }
    //                else if (strActualCtrlId == GlobalValues.ModifiedDate)
    //                {
    //                    txtObj.Enabled = false;
    //                }

    //                if (blnSeqControl)
    //                {
    //                    txtObj.Text = intCurrentRow.ToString();
    //                }
    //                if (!IsEdit) txtObj.Enabled = false;
    //                if (blnCaption)
    //                {
    //                    htc.Controls.Add(lblObj);
    //                }
    //                if (strPageView == "2")
    //                {
    //                    arlHtmlCells.Add(htc);
    //                    htc = new HtmlTableCell();
    //                }
    //                if (strCtrlId.ToLower() == "p_notes_notes")  // Added by srivatsan
    //                {
    //                    txtObj.Height = Unit.Pixel(150);
    //                }
    //                txtObj.CssClass = "controlFont controlWidth";
    //                htc.Controls.Add(txtObj);
    //                //loadDateTimeScript(droTemp, ref htc, txtObj.ID, ref DateTimestring);
    //                addDateIfDateTime(droTemp, ref htc, txtObj.ID);
    //                ///
    //                if (IsKey == "true")
    //                {
    //                    txtObj.BorderColor = cKey;
    //                    if (HttpContext.Current.Request.QueryString.Get("CPY") == null && HttpContext.Current.Request.QueryString.Get("PK") != null && !IsMutipleRecordPage)
    //                    {
    //                        txtObj.Enabled = false;
    //                    }
    //                    /*Label lblKey = new Label();
    //                    lblKey.ForeColor = System.Drawing.Color.Red;
    //                    lblKey.Text = "*";
    //                    htc.Controls.Add(lblKey);*/
    //                    //addMandatoryValidator(ref htc, txtObj);
    //                }
    //                if (IsPrimary=="true") addMandatoryValidator(ref htc, txtObj);
    //                arlHtmlCells.Add(htc);
    //                break;
    //            case "AN":
    //                htc = new HtmlTableCell();
    //                htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
    //                //htc.Controls.Add(new LiteralControl(strCtrlDesc + strBr));
    //                lblObj.ID = "lb_" + strCtrlId;
    //                lblObj.Text = strCtrlDesc + strBr;
    //                setLabelFont(ref lblObj);
    //                ////lblObj.Width = intLabelSize;
    //                txtObj = new TextBox();
    //                txtObj.ID = strCtrlId;
    //                txtObj.Text = getAutoNumberValue(ObjId, strActualCtrlId, intCurrentRow);
    //                txtObj.Enabled = false;
    //                if (tooltip != "")
    //                    txtObj.ToolTip = tooltip;//implemented by sanal on 11 Mar 2008
    //                if (strCtrlWidth != "")
    //                {
    //                    txtObj.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
    //                }
    //                if (strActualCtrlId == GlobalValues.CreatedDate)
    //                {
    //                    txtObj.Text = DateTime.Now.ToString();
    //                    txtObj.Enabled = false;
    //                }
    //                else if (strActualCtrlId == GlobalValues.ModifiedDate)
    //                {
    //                    txtObj.Enabled = false;
    //                }

    //                //if (droTemp["control_attrib_type"].ToString() == "NU" || droTemp["control_attrib_type"].ToString() == "DC" || droTemp["control_attrib_type"].ToString() == "CU" || droTemp["control_attrib_type"].ToString() == "AN")
    //                //    txtObj.Attributes["dir"] = "rtl";

    //                if (blnSeqControl)
    //                {
    //                    txtObj.Text = intCurrentRow.ToString();
    //                }
    //                if (blnCaption)
    //                {
    //                    htc.Controls.Add(lblObj);
    //                }
    //                if (strPageView == "2")
    //                {
    //                    arlHtmlCells.Add(htc);
    //                    htc = new HtmlTableCell();
    //                }
    //                txtObj.CssClass = "controlFont controlWidth";
    //                htc.Controls.Add(txtObj);
    //                ///
    //                if (IsKey == "true")
    //                {
    //                    txtObj.BorderColor = cKey;
    //                    if (HttpContext.Current.Request.QueryString.Get("CPY") == null && HttpContext.Current.Request.QueryString.Get("PK") != null && !IsMutipleRecordPage)
    //                    {
    //                        txtObj.Enabled = false;
    //                    }
    //                    /*Label lblKey = new Label();
    //                    lblKey.ForeColor = System.Drawing.Color.Red;
    //                    lblKey.Text = "*";
    //                    htc.Controls.Add(lblKey);*/
    //                    //addMandatoryValidator(ref htc, txtObj);
    //                }
    //                if (IsPrimary == "true") addMandatoryValidator(ref htc, txtObj);
    //                arlHtmlCells.Add(htc);
    //                break;
    //            case "CB":
    //                htc = new HtmlTableCell();
    //                //htc.VAlign = "middle";// Commented by srivatsan on Mar 19 2009
    //                htc.VAlign = "top";

    //                htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
    //                //htc.Controls.Add(new LiteralControl(strCtrlDesc + "<br>"));
    //                lblObj.ID = "lb_" + strCtrlId;
    //                lblObj.Text = strCtrlDesc + strBr;
    //                setLabelFont(ref lblObj);
    //                ////lblObj.Width = intLabelSize;
    //                CheckBox CB = new CheckBox();
    //                CB.ID = strCtrlId;
    //                //CB.Text = strCtrlDesc;
    //                CB.Checked = strDefaultVal.ToLower() == "true" ? true : false;
    //                if (tooltip != "")
    //                    CB.ToolTip = tooltip;//implemented by sanal on 11 Mar 2008
    //                if (blnSeqControl)
    //                {
    //                    CB.Text = intCurrentRow.ToString();
    //                }
    //                if (blnCaption)
    //                {
    //                    htc.Controls.Add(lblObj);
    //                }
    //                if (strPageView == "2")
    //                {
    //                    arlHtmlCells.Add(htc);
    //                    htc = new HtmlTableCell();
    //                }
    //                if (strDefaultVal != "")
    //                {
    //                    bool value = strDefaultVal.ToLower().Trim() == "1"||strDefaultVal.Trim().ToLower()=="true" ? true : false;
    //                    //CB.Checked = Convert.ToBoolean(strDefaultVal);
    //                    CB.Checked = value;
    //                }

    //                CB.CssClass = "controlFont";
    //                htc.Controls.Add(CB);
    //                if (!IsEdit) CB.Enabled = false;
    //                ///
    //                if (IsKey == "true")
    //                {
    //                    CB.BorderColor = cKey;
    //                    if (HttpContext.Current.Request.QueryString.Get("CPY") == null && HttpContext.Current.Request.QueryString.Get("PK") != null && !IsMutipleRecordPage)
    //                    {
    //                        CB.Enabled = false;
    //                    }
    //                    /*Label lblKey = new Label();
    //                    lblKey.ForeColor = System.Drawing.Color.Red;
    //                    lblKey.Text = "*";
    //                    htc.Controls.Add(lblKey);*/
    //                    //addMandatoryValidator(ref htc, CB);
    //                }
    //                //if (IsPrimary == "true") addMandatoryValidator(ref htc, CB);
    //                arlHtmlCells.Add(htc);
    //                break;
    //            case "DD":
    //                htc = new HtmlTableCell();
    //                //htc.VAlign = "middle"; //commented by srivatsan on Mar 19 2009
    //                htc.VAlign = "top";
    //                htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
    //                lblObj.ID = "lb_" + strCtrlId;
    //                lblObj.Text = strCtrlDesc + strBr;
    //                setLabelFont(ref lblObj);
    //                //lblObj.Width = intLabelSize;
    //                //htc.Controls.Add(new LiteralControl(strCtrlDesc + strBr));
    //                DropDownList DDL = new DropDownList();
    //                DDL.ID = strCtrlId;
    //                if (tooltip != "")
    //                    DDL.ToolTip = tooltip;//implemented by sanal on 11 Mar 2008
    //                if (strCtrlWidth != "")
    //                {
    //                    DDL.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
    //                }
    //                if (strBindRowID != "")
    //                {
    //                    BC.Bind(strBindRowID, DDL,ref dtBind);
    //                }
    //                if (strDefaultVal == "")
    //                {
    //                    if (blnSeqControl)
    //                    {
    //                        DDL.SelectedValue = intCurrentRow.ToString();
    //                    }
    //                    else
    //                    {
    //                        DDL.SelectedValue = "";
    //                    }
    //                }
    //                else
    //                {
    //                    try
    //                    {
    //                        if (strDefaultVal != "")
    //                        {
    //                            DDL.Items.FindByText(strDefaultVal).Selected = true; ;
    //                        }
    //                    }
    //                    catch (Exception e)
    //                    { }
    //                }
    //                //DDL.DataTextField = "Fld";
    //                //DDL.DataValueField = "Val";
    //                if (blnCaption)
    //                {
    //                    htc.Controls.Add(lblObj);
    //                }

    //                if (!IsEdit) DDL.Enabled = false;

    //                if (strPageView == "2")
    //                {
    //                    arlHtmlCells.Add(htc);
    //                    htc = new HtmlTableCell();
    //                }
    //                DDL.CssClass = "controlFont";
    //                SetDefaultValueForOwnerID(ref DDL, strActualCtrlId); // Added by srivatsan on June 25 2009
    //                htc.Controls.Add(DDL);
    //                //if (strBindRowID != "")//sanal
    //                //{
                        
    //                //        htc.Controls.Add(getBindDIV(DDL.ID, strBindRowID, dtBind, false));
    //                //        if (strActualCtrlId.ToLower() != ownerid)
    //                //        {
    //                //            htc.Controls.Add(getBindNewLink(strBindRowID, dtBind));
    //                //        }
    //                //        htc.Style.Add("white-space", "nowrap");
                        
    //                //}


    //                if (strBindRowID != "")//sanal
    //                {                   
    //                    htc.Controls.Add(getBindDIV(DDL.ID, strBindRowID, dtBind,false));
    //                    if (strActualCtrlId.ToLower() != ownerid)
    //                    {
                           
    //                        htc.Controls.Add(getBindNewLink(strBindRowID, dtBind));
    //                    }
    //                    htc.Style.Add("white-space", "nowrap");
                        

    //                }
    //                ///
    //                if (IsKey == "true")
    //                {
    //                    DDL.BorderColor = cKey;
    //                    if (HttpContext.Current.Request.QueryString.Get("CPY") == null && HttpContext.Current.Request.QueryString.Get("PK") != null && !IsMutipleRecordPage)
    //                    {
    //                        DDL.Enabled = false;
    //                    }
    //                    /*Label lblKey = new Label();
    //                    lblKey.ForeColor = System.Drawing.Color.Red;
    //                    lblKey.Text = "*";
    //                    htc.Controls.Add(lblKey);*/
    //                    //addMandatoryValidator(ref htc, DDL);
    //                }
    //                if (IsPrimary == "true") addMandatoryValidator(ref htc, DDL);
    //                htc.VAlign = "Top";
    //                arlHtmlCells.Add(htc);
    //                break;
    //            case "DA":
    //                htc = new HtmlTableCell();
    //                //htc.VAlign = "middle"; // commented by srivatsan
    //                htc.VAlign = "top";
    //                htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
    //                lblObj.ID = "lb_" + strCtrlId;
    //                lblObj.Text = strCtrlDesc + strBr;
    //                setLabelFont(ref lblObj);
    //                //lblObj.Width = intLabelSize;
    //                htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
    //                //htc.Controls.Add(new LiteralControl(strCtrlDesc + strBr));
    //                //C1WebDateEdit txtDAObj = new C1WebDateEdit();
    //                TextBox txtDAObj = new TextBox();
    //                txtDAObj.ID = strCtrlId;
    //                txtDAObj.Text = strDefaultVal;
    //                if (tooltip != "")
    //                    txtDAObj.ToolTip = tooltip;//implemented by sanal on 11 Mar 2008
    //                if (strCtrlWidth != "")
    //                {
    //                    txtDAObj.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
    //                }
    //                if (strActualCtrlId == GlobalValues.CreatedDate)
    //                {
    //                    txtDAObj.Text = DateTime.Now.ToString();
    //                    txtDAObj.Enabled = false;
    //                }
    //                else if (strActualCtrlId == GlobalValues.ModifiedDate)
    //                {
    //                    txtDAObj.Enabled = false;
    //                }
    //                if (blnCaption)
    //                {
    //                    htc.Controls.Add(lblObj);
    //                }

    //                if (!IsEdit) txtDAObj.Enabled = false;

    //                if (strPageView == "2")
    //                {
    //                    arlHtmlCells.Add(htc);
    //                    htc = new HtmlTableCell();
    //                }
    //                txtDAObj.CssClass = "controlFont controlWidth";
    //                htc.Controls.Add(txtDAObj);
    //                //loadDateTimeScript(droTemp, ref htc, txtDAObj.ID,ref DateTimestring);
    //                addDateIfDateTime(droTemp, ref htc, txtDAObj.ID);
    //                ///
    //                if (IsKey == "true")
    //                {
    //                    txtDAObj.BorderColor = cKey;
    //                    if (HttpContext.Current.Request.QueryString.Get("CPY") == null && HttpContext.Current.Request.QueryString.Get("PK") != null && !IsMutipleRecordPage)
    //                    {
    //                        txtDAObj.Enabled = false;
    //                    }
    //                    /*Label lblKey = new Label();
    //                    lblKey.ForeColor = System.Drawing.Color.Red;
    //                    lblKey.Text = "*";
    //                    htc.Controls.Add(lblKey);*/
    //                    //addMandatoryValidator(ref htc, txtDAObj);
    //                }
    //                if (IsPrimary == "true") addMandatoryValidator(ref htc, txtDAObj);
    //                arlHtmlCells.Add(htc);
    //                break;
    //            case "DT":
    //                htc = new HtmlTableCell();
    //                //htc.VAlign = "middle"; // Commented by srivatsan
    //                htc.VAlign = "top";
    //                htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
    //                lblObj.ID = "lb_" + strCtrlId;
    //                lblObj.Text = strCtrlDesc + strBr;
    //                setLabelFont(ref lblObj);
    //                //lblObj.Width = intLabelSize;
    //                htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
    //                //htc.Controls.Add(new LiteralControl(strCtrlDesc + strBr));
    //                //C1WebDateEdit txtDTObj = new C1WebDateEdit();
    //                TextBox txtDTObj = new TextBox();
    //                txtDTObj.ID = strCtrlId;
    //                txtDTObj.Text = strDefaultVal;
    //                if (tooltip != "")
    //                    txtDTObj.ToolTip = tooltip;//implemented by sanal on 11 Mar 2008
    //                if (strCtrlWidth != "")
    //                {
    //                    txtDTObj.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
    //                }
    //                if (strActualCtrlId == GlobalValues.CreatedDate)
    //                {
    //                    txtDTObj.Text = DateTime.Now.ToString();
    //                    txtDTObj.Enabled = false;
    //                }
    //                else if (strActualCtrlId == GlobalValues.ModifiedDate)
    //                {
    //                    txtDTObj.Enabled = false;
    //                }

    //                if (blnCaption)
    //                {
    //                    htc.Controls.Add(lblObj);
    //                }

    //                if (!IsEdit) txtDTObj.Enabled = false;

    //                if (strPageView == "2")
    //                {
    //                    arlHtmlCells.Add(htc);
    //                    htc = new HtmlTableCell();
    //                }
    //                txtDTObj.CssClass = "controlFont controlWidth";
    //                htc.Controls.Add(txtDTObj);
    //                //loadDateTimeScript(droTemp, ref htc, txtDTObj.ID, ref DateTimestring);
    //                addDateIfDateTime(droTemp, ref htc, txtDTObj.ID);
    //                ///
    //                if (IsKey == "true")
    //                {
    //                    txtDTObj.BorderColor = cKey;
    //                    if (HttpContext.Current.Request.QueryString.Get("CPY") == null && HttpContext.Current.Request.QueryString.Get("PK") != null && !IsMutipleRecordPage)
    //                    {
    //                        txtDTObj.Enabled = false;
    //                    }
    //                    /*Label lblKey = new Label();
    //                    lblKey.ForeColor = System.Drawing.Color.Red;
    //                    lblKey.Text = "*";
    //                    htc.Controls.Add(lblKey);*/
    //                    //addMandatoryValidator(ref htc, txtDTObj);
    //                }
    //                if (IsPrimary == "true") addMandatoryValidator(ref htc, txtDTObj);
    //                arlHtmlCells.Add(htc);
    //                break;
    //            case "PW":
    //                htc = new HtmlTableCell();
    //                //htc.VAlign = "middle"; // Commented by srivatsan on Mar 19 2009
    //                htc.VAlign = "top";


    //                htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
    //                //htc.Controls.Add(new LiteralControl(strCtrlDesc + strBr));
    //                lblObj.ID = "lb_" + strCtrlId;
    //                lblObj.Text = strCtrlDesc + strBr;
    //                setLabelFont(ref lblObj);
    //                ////lblObj.Width = intLabelSize;
    //                txtObj = new TextBox();
    //                txtObj.TextMode = TextBoxMode.Password;
    //                txtObj.ID = strCtrlId;
    //                txtObj.Text = strDefaultVal;
    //                if (tooltip != "")
    //                    txtObj.ToolTip = tooltip;//implemented by sanal on 11 Mar 2008
    //                if (strCtrlWidth != "")
    //                {
    //                    txtObj.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
    //                }
    //                if (strActualCtrlId == GlobalValues.CreatedDate)
    //                {
    //                    txtObj.Text = DateTime.Now.ToString();
    //                    txtObj.Enabled = false;
    //                }
    //                else if (strActualCtrlId == GlobalValues.ModifiedDate)
    //                {
    //                    txtObj.Enabled = false;
    //                }

    //                if (Attrib_Size != "")
    //                    txtObj.MaxLength = Convert.ToInt32(Attrib_Size);

    //                if (blnSeqControl)
    //                {
    //                    txtObj.Text = intCurrentRow.ToString();
    //                }

    //                txtObj.Attributes.Add("class", "controlFont controlWidth");
    //                //txtObj.Attributes.Add("style","text-align:right");
    //                //if (droTemp["control_attrib_type"].ToString() == "NU" || droTemp["control_attrib_type"].ToString() == "DC" || droTemp["control_attrib_type"].ToString() == "CU")
    //                //    txtObj.Attributes["dir"] = "rtl";

    //                if (!IsEdit) txtObj.Enabled = false;
    //                if (blnCaption)
    //                {
    //                    htc.Controls.Add(lblObj);
    //                }
    //                if (strPageView == "2")
    //                {
    //                    arlHtmlCells.Add(htc);
    //                    htc = new HtmlTableCell();
    //                }
    //                Literal l = new Literal();
    //                l.Text = "&nbsp;<img src=\"Images/key.gif\" alt=\"Password Field\" border=\"0\" />";
    //                htc.Controls.Add(txtObj);
    //                htc.Controls.Add(l);
    //                //loadDateTimeScript(droTemp, ref htc, txtObj.ID,ref DateTimestring);
    //                addDateIfDateTime(droTemp, ref htc, txtObj.ID);
    //                ///
    //                if (strBindRowID != "")//sanal
    //                {
    //                    htc.Controls.Add(getBindDIV(txtObj.ID, strBindRowID, null, true));
    //                    htc.Controls.Add(getBindNewLink(strBindRowID, null));
    //                    htc.Style.Add("white-space", "nowrap");
    //                }
    //                if (IsKey == "true")
    //                {
    //                    txtObj.BorderColor = cKey;
    //                    if (HttpContext.Current.Request.QueryString.Get("CPY") == null && HttpContext.Current.Request.QueryString.Get("PK") != null && !IsMutipleRecordPage)
    //                    {
    //                        txtObj.Enabled = false;
    //                    }
    //                    /*Label lblKey = new Label();
    //                    lblKey.ForeColor = System.Drawing.Color.Red;
    //                    lblKey.Text = "*";
    //                    htc.Controls.Add(lblKey);*/
    //                    //addMandatoryValidator(ref htc, txtObj);
    //                }
    //                if (IsPrimary == "true") addMandatoryValidator(ref htc, txtObj);
    //                if (inputMask != "") processInputMask(ref htc, txtObj, inputMask);
    //                arlHtmlCells.Add(htc);
    //                break;
    //            default:
    //                htc = new HtmlTableCell();
    //                htc.VAlign = "top";
    //                htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
    //                //htc.Controls.Add(new LiteralControl(strCtrlDesc + strBr));
    //                lblObj.ID = "lb_" + strCtrlId;
    //                lblObj.Text = strCtrlDesc + strBr;
    //                setLabelFont(ref lblObj);
    //                lblObj.Font.Bold = true;
    //                ////lblObj.Width = intLabelSize;
    //                Label txtObj1 = new Label();
    //                txtObj1.ID = strCtrlId;
    //                txtObj1.Text = strDefaultVal;                    
    //                if (tooltip != "")
    //                    txtObj1.ToolTip = tooltip;//implemented by sanal on 11 Mar 2008
    //                if (strCtrlWidth != "")
    //                {
    //                    txtObj1.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
    //                }
    //                if (strActualCtrlId == GlobalValues.CreatedDate)
    //                {
    //                    txtObj1.Text = DateTime.Now.ToString();
    //                    txtObj1.Enabled = false;
    //                }
    //                else if (strActualCtrlId == GlobalValues.ModifiedDate)
    //                {
    //                    txtObj1.Enabled = false;
    //                }

    //                if (blnSeqControl)
    //                {
    //                    txtObj1.Text = intCurrentRow.ToString();
    //                }
    //                if (blnCaption)
    //                {
    //                    htc.Controls.Add(lblObj);
    //                }
    //                if (strPageView == "2")
    //                {
    //                    arlHtmlCells.Add(htc);
    //                    htc = new HtmlTableCell();
    //                }
    //                txtObj1.CssClass = "controlFont controlWidth";
    //                htc.Controls.Add(txtObj1);
    //                arlHtmlCells.Add(htc);
    //                break;
    //        }
    //    }
    //    dtBind = null;
    //    return arlHtmlCells;

    //}

    public string GetHtmlTableCellClassName(DataSet dsInput)
    {
        string result = "Dynamic_HtmlTableCell";
        try
        {
            if (dsInput != null) // Check for transaction document
            {
                result = "Dynamic_TransDocHtmlTableCell";
            }
        }
        catch
        {

        }
        return result;
    }

    public ArrayList ControlInit(HtmlTableCell htc, int intCurrentRow, String strPageView, string strCtrlId, string strCtrlDesc,
         string strBindRowID, string strCtrlHtml, ArrayList arlHtmlCells, bool blnSeqControl, BindControl BC, string strDefaultVal,
         bool blnCaption, string strActualCtrlId, string strCtrlWidth, string ObjId, string IsKey, string IsPrimary,
        bool IsMutipleRecordPage, bool IsEdit, string Attrib_Size, DataRow droTemp, DataTable dtPageKeys, string IsRelationalField, string tooltip, string inputMask, DataSet dsInput,DataRow[] drTotals,HtmlForm frmtotals,DataSet dsTax,string strpageid)
    {
        string strBr = ""; DataTable dtBind = new DataTable();
        System.Drawing.Color cKey = System.Drawing.Color.Gray;
        if (strPageView == "1")
        {
            strBr = "<br>";
        }

        if (strDefaultVal.StartsWith("{!") && strDefaultVal.EndsWith("}"))
        {
            //strDefaultVal = strDefaultVal.Substring(2, strDefaultVal.Length - 2 - 1);
            Hashtable hsSysVar = (Hashtable)HttpContext.Current.Session["SysVar"];
            if (hsSysVar.Contains(strDefaultVal))
                strDefaultVal = hsSysVar[strDefaultVal].ToString();
            /*if (GlobalValues.hsSysVar.Contains(strDefaultVal))
                strDefaultVal = GlobalValues.hsSysVar[strDefaultVal].ToString();*/
        }
        else if (strDefaultVal.StartsWith("{@") && strDefaultVal.EndsWith("}"))
        {
            security hds = new security();
            Hashtable hsAppVar = new Hashtable();
            hds.loadAppVariables(ref hsAppVar);
            hds = null;
            if (hsAppVar.Contains(strDefaultVal))
                strDefaultVal = hsAppVar[strDefaultVal].ToString();
            //if (GlobalValues.hsAppVar.Contains(strDefaultVal))
            //    strDefaultVal = GlobalValues.hsAppVar[strDefaultVal].ToString();
        }
        else if (strDefaultVal == "CurrentDate()")
        {
            strDefaultVal = DateTime.Now.ToShortDateString();
            strDefaultVal = MBLocalization.getLocalizedDate(HttpContext.Current.Session["userlocale"].ToString(), DateTime.Parse(strDefaultVal));
        }
        Control con;
        string sBindText = "";

        if (!CreateMasterDetailControl(ref arlHtmlCells, strActualCtrlId, strCtrlId, strCtrlDesc, strBr, strCtrlWidth, blnCaption, strPageView, dtPageKeys, strDefaultVal,dsInput))
        //if (arlHtmlCells.Count == 0)
        {
            Label lblObj = new Label();

                switch (strCtrlHtml.ToUpper())
            {
                case "TB":
                case "EM":
                    security sec = new security();
                    bool change_owner = false;
                    if (strActualCtrlId.ToLower() == ownerid)
                    {
                        change_owner = sec.getRightsForMRUObjects(HttpContext.Current.Request.QueryString["pgs_id"].ToString(), "change_owner");
                    }

                    sec = null;

                    htc = new HtmlTableCell();
                    //htc.VAlign = "middle"; // commented by srivatsan
                    htc.VAlign = "top";
                    //htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
                    htc.Attributes.Add("Class", GetHtmlTableCellClassName(dsInput));
                    //htc.Controls.Add(new LiteralControl(strCtrlDesc + strBr));
                    lblObj.ID = "lb_" + strCtrlId;
                    lblObj.Text = HttpUtility.HtmlEncode(strCtrlDesc) + strBr;
                    setLabelFont(ref lblObj);
                    if (dsInput != null)
                    {
                        lblObj.Visible = false;
                    }
                    ////lblObj.Width = intLabelSize;
                    TextBox txtObj = new TextBox();
                    txtObj.ID = strCtrlId;
                    if (strBindRowID != "") //Srivatsan on July 16 2009
                    {
                        txtObj.ID = "txt_" + strCtrlId;
                    }
                    if (HttpContext.Current.Request.QueryString["PK"] == null) // Added by srivatsan
                    {
                        try
                        {
                            if (strDefaultVal != "")
                            {
                                switch (droTemp["control_attrib_type"].ToString().ToLower())
                                {
                                    case "dt":
                                    case "da":
                                        txtObj.Text = MBLocalization.getLocalizedDate(HttpContext.Current.Session["userlocale"].ToString(), DateTime.Parse(strDefaultVal));
                                        break;
                                    case "nu":
                                    case "an":
                                        txtObj.Text = MBLocalization.getLocalizedInteger(HttpContext.Current.Session["userlocale"].ToString(), int.Parse(strDefaultVal));
                                        break;
                                    case "cu":
                                    case "dc":
                                    case "fl":
                                        txtObj.Text = MBLocalization.getLocalizedDecimal(HttpContext.Current.Session["userlocale"].ToString(), double.Parse(strDefaultVal));
                                        break;
                                    default:
                                        txtObj.Text = strDefaultVal;
                                        break;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            txtObj.Text = strDefaultVal;
                        }
                    }
                    
                    
                    con = (Control)txtObj;
                    SetValuesforTransactionDocument("TB", dsInput, drTotals, ref sBindText, frmtotals, strActualCtrlId, ref con, intCurrentRow, ref strBindRowID, droTemp);

                    if (tooltip != "")
                        txtObj.ToolTip = tooltip;//implemented by sanal on 11 Mar 2008
                    if (strCtrlWidth != "")
                    {
                        txtObj.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
                    }
                    if (strActualCtrlId == GlobalValues.CreatedDate)
                    {
                        txtObj.Text = DateTime.Now.ToString();
                        txtObj.Enabled = false;
                    }
                    else if (strActualCtrlId == GlobalValues.ModifiedDate)
                    {
                        txtObj.Enabled = false;
                    }

                    if (Attrib_Size != "")
                        txtObj.MaxLength = Convert.ToInt32(Attrib_Size);

                    if (blnSeqControl)
                    {
                        txtObj.Text = intCurrentRow.ToString();
                    }
                    //txtObj.Attributes.Add("style","text-align:right");
                    //if (droTemp["control_attrib_type"].ToString() == "NU" || droTemp["control_attrib_type"].ToString() == "DC" || droTemp["control_attrib_type"].ToString() == "CU")
                    //    txtObj.Attributes["dir"] = "rtl";

                    if (!IsEdit) txtObj.Enabled = false;
                    if (strActualCtrlId.ToLower() == ownerid)
                    {
                        if (!change_owner)
                        {
                            txtObj.Enabled = false;
                        }
                    }
                    if (blnCaption)
                    {
                        htc.Controls.Add(lblObj);
                    }
                    if (strPageView == "2")
                    {
                        arlHtmlCells.Add(htc);
                        htc = new HtmlTableCell();
                    }
                    if (dsInput != null)
                    {
                        if (strActualCtrlId.ToLower() == "owner_id")
                        {
                            txtObj.Visible = false;
                        }
                    }
                    txtObj.CssClass = "controlFont controlWidth";
                    htc.Controls.Add(txtObj);
                    if (strBindRowID != "")
                    {
                        HiddenField hf = new HiddenField();
                        hf.ID = strCtrlId;
                        SetDefaultValueForOwnerID(ref txtObj, ref hf, strActualCtrlId);
                        htc.Controls.Add(hf);
                    }
                    // txtObj.Width = Unit.Pixel(225); //srivatsan

                    //loadDateTimeScript(droTemp, ref htc, txtObj.ID,ref DateTimestring);
                    addDateIfDateTime(droTemp, ref htc, txtObj.ID);
                    ///
                    if (strBindRowID != "")//sanal
                    {
                        //htc.Controls.Add(getBindDIV(txtObj.ID, strBindRowID, null,true)); // Commented by srivatsan on July 16 2009
                        if (!isViewMode())
                        {
                            if (strActualCtrlId.ToLower() == ownerid)
                            {
                                if (dsInput == null)
                                {
                                    if (change_owner)
                                    {
                                        AddSearchLink(ref htc, strActualCtrlId, strCtrlId, txtObj.ID, strBindRowID); // added by srivatsan on july 15 2009
                                    }
                                }
                            }
                            else
                            {
                                AddSearchLink(ref htc, strActualCtrlId, strCtrlId, txtObj.ID, strBindRowID); // added by srivatsan on july 15 2009}
                            }
                        }
                        if (strActualCtrlId != ownerid)
                        {
                            htc.Controls.Add(getBindNewLink(strBindRowID, null));
                        }
                        htc.Style.Add("white-space", "nowrap");
                        txtObj.Style.Add("vertical-align", "middle");

                    }

                    if (IsKey == "true")
                    {
                        txtObj.BorderColor = cKey;
                        if (HttpContext.Current.Request.QueryString.Get("CPY") == null && HttpContext.Current.Request.QueryString.Get("PK") != null && !IsMutipleRecordPage)
                        {
                            txtObj.Enabled = false;
                        }
                        /*Label lblKey = new Label();
                        lblKey.ForeColor = System.Drawing.Color.Red;
                        lblKey.Text = "*";
                        htc.Controls.Add(lblKey);*/
                        //addMandatoryValidator(ref htc, txtObj);
                    }
                    if (IsPrimary == "true")
                    {
                        if (dsInput == null)
                        {
                            addMandatoryValidator(ref htc, txtObj);
                        }
                    }
                    if (inputMask != "") processInputMask(ref htc, txtObj, inputMask);
                    if (strCtrlHtml.ToUpper() == "EM")
                    {
                        if (dsInput != null)
                        {
                            if (dsInput.Tables.Count > 0)
                            {
                                string af_row_id = dsInput.Tables[0].Rows[intCurrentRow - 1]["af_row_id"].ToString();
                                //provideEmailValidation(ref htc, txtObj, strActualCtrlId, droTemp, af_row_id);
                                provideEmailValidation(ref htc, txtObj, strActualCtrlId, droTemp, af_row_id, dtPageKeys, strpageid);//Bala on Nov 30,2011 dtPageKeys, strpageid parameter added during Email Logo showing
                            }
                        }
                        else
                            provideEmailValidation(ref htc, txtObj, strActualCtrlId, droTemp, "", dtPageKeys, strpageid);//,droTemp,strpageid,intCurrentRow);//sanal on Nov 04, 2009//Bala on Nov 30,2011 dtPageKeys, strpageid parameter added during Email Logo showing
                            //provideEmailValidation(ref htc, txtObj, strActualCtrlId, droTemp, "");//,droTemp,strpageid,intCurrentRow);//sanal on Nov 04, 2009
                    }
                    htc.VAlign = "top"; // Added bysrivatsan on mar 19 2009
                    arlHtmlCells.Add(htc);
                    break;
                case "TA":
                    htc = new HtmlTableCell();
                    // htc.VAlign = "middle";  // Commented by srivatsan on Mar 19 2009
                    htc.VAlign = "top";
                    //htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
                    htc.Attributes.Add("Class", GetHtmlTableCellClassName(dsInput));
                    //htc.Controls.Add(new LiteralControl(strCtrlDesc + strBr));
                    lblObj.ID = "lb_" + strCtrlId;
                    lblObj.Text = strCtrlDesc + strBr;
                    setLabelFont(ref lblObj);
                    if (dsInput != null)
                    {
                        lblObj.Visible = false;
                    }
                    ////lblObj.Width = intLabelSize;
                    txtObj = new TextBox();
                    txtObj.TextMode = TextBoxMode.MultiLine;
                    txtObj.Rows = 4;
                    txtObj.ID = strCtrlId;
                    if (HttpContext.Current.Request.QueryString["PK"] == null) // Added by srivatsan
                        txtObj.Text = strDefaultVal;
                    

                    con = (Control)txtObj;
                    SetValuesforTransactionDocument("TA", dsInput, drTotals, ref sBindText, frmtotals, strActualCtrlId, ref con, intCurrentRow, ref strBindRowID, droTemp);

                    if (tooltip != "")
                        txtObj.ToolTip = tooltip;//implemented by sanal on 11 Mar 2008
                    if (strCtrlWidth != "")
                    {
                        txtObj.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
                    }
                    if (strActualCtrlId == GlobalValues.CreatedDate)
                    {
                        txtObj.Text = DateTime.Now.ToString();
                        txtObj.Enabled = false;
                    }
                    else if (strActualCtrlId == GlobalValues.ModifiedDate)
                    {
                        txtObj.Enabled = false;
                    }

                    if (blnSeqControl)
                    {
                        txtObj.Text = intCurrentRow.ToString();
                    }
                    if (!IsEdit) txtObj.Enabled = false;
                    if (blnCaption)
                    {
                        htc.Controls.Add(lblObj);
                    }
                    if (strPageView == "2")
                    {
                        arlHtmlCells.Add(htc);
                        htc = new HtmlTableCell();
                    }
                    if (strCtrlId.ToLower() == "p_notes_notes")  // Added by srivatsan
                    {
                        txtObj.Height = Unit.Pixel(150);
                    }
                    txtObj.CssClass = "controlFont controlWidth";
                    htc.Controls.Add(txtObj);
                    //loadDateTimeScript(droTemp, ref htc, txtObj.ID, ref DateTimestring);
                    addDateIfDateTime(droTemp, ref htc, txtObj.ID);
                    ///
                    if (IsKey == "true")
                    {
                        txtObj.BorderColor = cKey;
                        if (HttpContext.Current.Request.QueryString.Get("CPY") == null && HttpContext.Current.Request.QueryString.Get("PK") != null && !IsMutipleRecordPage)
                        {
                            txtObj.Enabled = false;
                        }
                        /*Label lblKey = new Label();
                        lblKey.ForeColor = System.Drawing.Color.Red;
                        lblKey.Text = "*";
                        htc.Controls.Add(lblKey);*/
                        //addMandatoryValidator(ref htc, txtObj);
                    }
                    if (IsPrimary == "true")
                    {
                        if (dsInput == null)
                        {
                            addMandatoryValidator(ref htc, txtObj);
                        }
                    }
                    arlHtmlCells.Add(htc);
                    break;
                case "AN":
                    htc = new HtmlTableCell();
                   // htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
                    htc.Attributes.Add("Class", GetHtmlTableCellClassName(dsInput));
                    //htc.Controls.Add(new LiteralControl(strCtrlDesc + strBr));
                    lblObj.ID = "lb_" + strCtrlId;
                    lblObj.Text = strCtrlDesc + strBr;
                    setLabelFont(ref lblObj);
                    if (dsInput != null)
                    {
                        lblObj.Visible = false;
                    }
                    ////lblObj.Width = intLabelSize;
                    txtObj = new TextBox();
                    txtObj.ID = strCtrlId;
                    txtObj.Text = getAutoNumberValue(ObjId, strActualCtrlId, intCurrentRow);
                    txtObj.Enabled = false;
                    if (tooltip != "")
                        txtObj.ToolTip = tooltip;//implemented by sanal on 11 Mar 2008
                    if (strCtrlWidth != "")
                    {
                        txtObj.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
                    }
                    if (strActualCtrlId == GlobalValues.CreatedDate)
                    {
                        txtObj.Text = DateTime.Now.ToString();
                        txtObj.Enabled = false;
                    }
                    else if (strActualCtrlId == GlobalValues.ModifiedDate)
                    {
                        txtObj.Enabled = false;
                    }

                    //if (droTemp["control_attrib_type"].ToString() == "NU" || droTemp["control_attrib_type"].ToString() == "DC" || droTemp["control_attrib_type"].ToString() == "CU" || droTemp["control_attrib_type"].ToString() == "AN")
                    //    txtObj.Attributes["dir"] = "rtl";

                    if (blnSeqControl)
                    {
                        txtObj.Text = intCurrentRow.ToString();
                    }
                    if (blnCaption)
                    {
                        htc.Controls.Add(lblObj);
                    }
                    if (strPageView == "2")
                    {
                        arlHtmlCells.Add(htc);
                        htc = new HtmlTableCell();
                    }
                    txtObj.CssClass = "controlFont controlWidth";
                    htc.Controls.Add(txtObj);
                    ///
                    if (IsKey == "true")
                    {
                        txtObj.BorderColor = cKey;
                        if (HttpContext.Current.Request.QueryString.Get("CPY") == null && HttpContext.Current.Request.QueryString.Get("PK") != null && !IsMutipleRecordPage)
                        {
                            txtObj.Enabled = false;
                        }
                        /*Label lblKey = new Label();
                        lblKey.ForeColor = System.Drawing.Color.Red;
                        lblKey.Text = "*";
                        htc.Controls.Add(lblKey);*/
                        //addMandatoryValidator(ref htc, txtObj);
                    }
                    if (IsPrimary == "true")
                    {
                        if (dsInput == null)
                        {
                            addMandatoryValidator(ref htc, txtObj);
                        }
                    }
                    arlHtmlCells.Add(htc);
                    break;
                case "CB":
                    htc = new HtmlTableCell();
                    //htc.VAlign = "middle";// Commented by srivatsan on Mar 19 2009
                    htc.VAlign = "top";

                    //htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
                    htc.Attributes.Add("Class", GetHtmlTableCellClassName(dsInput));
                    //htc.Controls.Add(new LiteralControl(strCtrlDesc + "<br>"));
                    lblObj.ID = "lb_" + strCtrlId;
                    lblObj.Text = strCtrlDesc + strBr;
                    setLabelFont(ref lblObj);
                    if (dsInput != null)
                    {
                        lblObj.Visible = false;
                    }
                    ////lblObj.Width = intLabelSize;
                    CheckBox CB = new CheckBox();
                    CB.ID = strCtrlId;
                    //CB.Text = strCtrlDesc;
                    if (HttpContext.Current.Request.QueryString["PK"] == null) // Added by srivatsan
                        CB.Checked = strDefaultVal.ToLower() == "true" ? true : false;

                    con = (Control)CB;
                    SetValuesforTransactionDocument("CB", dsInput, drTotals, ref sBindText, frmtotals, strActualCtrlId, ref con, intCurrentRow, ref strBindRowID, droTemp);

                    if (tooltip != "")
                        CB.ToolTip = tooltip;//implemented by sanal on 11 Mar 2008
                    if (blnSeqControl)
                    {
                        CB.Text = intCurrentRow.ToString();
                    }
                    if (blnCaption)
                    {
                        htc.Controls.Add(lblObj);
                    }
                    if (strPageView == "2")
                    {
                        arlHtmlCells.Add(htc);
                        htc = new HtmlTableCell();
                    }
                    if (HttpContext.Current.Request.QueryString["PK"] == null) // Added by srivatsan
                        if (strDefaultVal != "")
                        {
                            bool value = strDefaultVal.ToLower().Trim() == "1" || strDefaultVal.Trim().ToLower() == "true" ? true : false;
                            //CB.Checked = Convert.ToBoolean(strDefaultVal);
                            CB.Checked = value;
                        }

                    CB.CssClass = "controlFont";
                    htc.Controls.Add(CB);
                    if (!IsEdit) CB.Enabled = false;
                    ///
                    if (IsKey == "true")
                    {
                        CB.BorderColor = cKey;
                        if (HttpContext.Current.Request.QueryString.Get("CPY") == null && HttpContext.Current.Request.QueryString.Get("PK") != null && !IsMutipleRecordPage)
                        {
                            CB.Enabled = false;
                        }
                        /*Label lblKey = new Label();
                        lblKey.ForeColor = System.Drawing.Color.Red;
                        lblKey.Text = "*";
                        htc.Controls.Add(lblKey);*/
                        //addMandatoryValidator(ref htc, CB);
                    }
                    //if (IsPrimary == "true") addMandatoryValidator(ref htc, CB);
                    arlHtmlCells.Add(htc);
                    break;
                case "DD":
                case "DDE":
                    ////bool isDDE = false;
                    ////if (strCtrlHtml.ToUpper() == "DDE")
                    ////    isDDE = true;
                    htc = new HtmlTableCell();
                    //htc.VAlign = "middle"; //commented by srivatsan on Mar 19 2009
                    htc.VAlign = "top";
                    //htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
                    htc.Attributes.Add("Class", GetHtmlTableCellClassName(dsInput));
                    lblObj.ID = "lb_" + strCtrlId;
                    lblObj.Text = strCtrlDesc + strBr;
                    setLabelFont(ref lblObj);
                    if (dsInput != null)
                    {
                        lblObj.Visible = false;
                    }
                    //lblObj.Width = intLabelSize;
                    //htc.Controls.Add(new LiteralControl(strCtrlDesc + strBr));
                    DropDownList DDL = new DropDownList();
                    DDL.ID = strCtrlId;
                    if (tooltip != "")
                        DDL.ToolTip = tooltip;//implemented by sanal on 11 Mar 2008
                    if (strCtrlWidth != "")
                    {
                        DDL.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
                    }
                    string[] BindFields = null;
                    if (strCtrlHtml.ToUpper() == "DDE") // Added by srivatsan for DDE changes on Jan 5 2010
                    {
                        //BindFields = GetBindFields(strBindRowID);
                        HDDatabase HDD = new HDDatabase();
                        string bindvalue = HDD.GetColumnValue("select bind_value from sy_bnd where af_row_id = '"+strBindRowID+"'");
                        string bindtext = HDD.GetColumnValue("select bind_text from sy_bnd where af_row_id = '" + strBindRowID + "'");
                        BindFields = GetBindFields(strBindRowID,bindvalue,bindtext,true);
                        ConfigureDDE(ref DDL, droTemp, strBindRowID, ref htc,frmtotals,BindFields);
                    }
                    else
                    {
                        if (strBindRowID != "")
                        {
                            BC.Bind(strBindRowID, DDL, ref dtBind, null);
                        }
                    }

                    if (HttpContext.Current.Request.QueryString["PK"] == null) // Added by srivatsan
                    {
                        if(strCtrlHtml.ToUpper()!="DDE")
                        if (strDefaultVal == "")
                        {
                            if (blnSeqControl)
                            {
                                DDL.SelectedValue = intCurrentRow.ToString();
                            }
                            else
                            {
                                DDL.SelectedValue = "";
                            }
                        }
                        else
                        {
                            try
                            {
                                if (strDefaultVal != "")
                                {
                                    DDL.Items.FindByText(strDefaultVal).Selected = true; ;
                                }
                            }
                            catch (Exception e)
                            { }
                        }
                    }
                    con = (Control)DDL;
                    SetValuesforTransactionDocument("DD", dsInput, drTotals, ref sBindText, frmtotals, strActualCtrlId, ref con, intCurrentRow, ref strBindRowID, droTemp);

                    //DDL.DataTextField = "Fld";
                    //DDL.DataValueField = "Val";
                    if (blnCaption)
                    {
                        htc.Controls.Add(lblObj);
                    }

                    if (!IsEdit) DDL.Enabled = false;

                    if (strPageView == "2")
                    {
                        arlHtmlCells.Add(htc);
                        htc = new HtmlTableCell();
                    }
                    DDL.CssClass = "controlFont";
                    SetDefaultValueForOwnerID(ref DDL, strActualCtrlId); // Added by srivatsan on June 25 2009
                    htc.Controls.Add(DDL);

                    //if (strBindRowID != "")//sanal
                    //{

                    //        htc.Controls.Add(getBindDIV(DDL.ID, strBindRowID, dtBind, false));
                    //        if (strActualCtrlId.ToLower() != ownerid)
                    //        {
                    //            htc.Controls.Add(getBindNewLink(strBindRowID, dtBind));
                    //        }
                    //        htc.Style.Add("white-space", "nowrap");

                    //}


                    if (strBindRowID != "")//sanal
                    {
                        htc.Controls.Add(getBindDIV(DDL.ID, strBindRowID, dtBind, false));
                        if (strActualCtrlId.ToLower() != ownerid)
                        {

                            htc.Controls.Add(getBindNewLink(strBindRowID, dtBind));
                        }
                        htc.Style.Add("white-space", "nowrap");
                        DDL.Style.Add("vertical-align", "middle");

                    }
                    ///
                    if (IsKey == "true")
                    {
                        DDL.BorderColor = cKey;
                        if (HttpContext.Current.Request.QueryString.Get("CPY") == null && HttpContext.Current.Request.QueryString.Get("PK") != null && !IsMutipleRecordPage)
                        {
                            DDL.Enabled = false;
                        }
                        /*Label lblKey = new Label();
                        lblKey.ForeColor = System.Drawing.Color.Red;
                        lblKey.Text = "*";
                        htc.Controls.Add(lblKey);*/
                        //addMandatoryValidator(ref htc, DDL);
                    }
                    if (strCtrlHtml.ToUpper() == "DDE")    //Added by srivatsan for DDE changes
                        AddDDEEditButton(ref htc, ref DDL, strCtrlId, strBindRowID,BindFields);
                    if (IsPrimary == "true")
                    {
                        if (dsInput == null)
                        {
                            addMandatoryValidator(ref htc, DDL);
                        }
                    }
                    htc.VAlign = "Top";
                    arlHtmlCells.Add(htc);
                    break;
                case "DA":
                    htc = new HtmlTableCell();
                    //htc.VAlign = "middle"; // commented by srivatsan
                    htc.VAlign = "top";
                    //htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
                    htc.Attributes.Add("Class", GetHtmlTableCellClassName(dsInput));
                    lblObj.ID = "lb_" + strCtrlId;
                    lblObj.Text = strCtrlDesc + strBr;
                    setLabelFont(ref lblObj);
                    if (dsInput != null)
                    {
                        lblObj.Visible = false;
                    }
                    //lblObj.Width = intLabelSize;
                    //htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
                    htc.Attributes.Add("Class", GetHtmlTableCellClassName(dsInput));
                    //htc.Controls.Add(new LiteralControl(strCtrlDesc + strBr));
                    //C1WebDateEdit txtDAObj = new C1WebDateEdit();
                    TextBox txtDAObj = new TextBox();
                    txtDAObj.ID = strCtrlId;
                    if (HttpContext.Current.Request.QueryString["PK"] == null) // Added by srivatsan
                        txtDAObj.Text = strDefaultVal;
                    if (tooltip != "")
                        txtDAObj.ToolTip = tooltip;//implemented by sanal on 11 Mar 2008
                    if (strCtrlWidth != "")
                    {
                        txtDAObj.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
                    }
                    if (strActualCtrlId == GlobalValues.CreatedDate)
                    {
                        txtDAObj.Text = DateTime.Now.ToString();
                        txtDAObj.Enabled = false;
                    }
                    else if (strActualCtrlId == GlobalValues.ModifiedDate)
                    {
                        txtDAObj.Enabled = false;
                    }
                    if (blnCaption)
                    {
                        htc.Controls.Add(lblObj);
                    }

                    if (!IsEdit) txtDAObj.Enabled = false;

                    if (strPageView == "2")
                    {
                        arlHtmlCells.Add(htc);
                        htc = new HtmlTableCell();
                    }

                    con = (Control)txtDAObj;
                    SetValuesforTransactionDocument("DA", dsInput, drTotals, ref sBindText, frmtotals, strActualCtrlId, ref con, intCurrentRow, ref strBindRowID, droTemp);

                    txtDAObj.CssClass = "controlFont controlWidth";
                    htc.Controls.Add(txtDAObj);
                    //loadDateTimeScript(droTemp, ref htc, txtDAObj.ID,ref DateTimestring);
                    addDateIfDateTime(droTemp, ref htc, txtDAObj.ID);
                    ///
                    if (IsKey == "true")
                    {
                        txtDAObj.BorderColor = cKey;
                        if (HttpContext.Current.Request.QueryString.Get("CPY") == null && HttpContext.Current.Request.QueryString.Get("PK") != null && !IsMutipleRecordPage)
                        {
                            txtDAObj.Enabled = false;
                        }
                        /*Label lblKey = new Label();
                        lblKey.ForeColor = System.Drawing.Color.Red;
                        lblKey.Text = "*";
                        htc.Controls.Add(lblKey);*/
                        //addMandatoryValidator(ref htc, txtDAObj);
                    }
                    if (IsPrimary == "true")
                    {
                        if (dsInput == null)
                        {
                            addMandatoryValidator(ref htc, txtDAObj);
                        }
                    }
                    arlHtmlCells.Add(htc);
                    break;
                case "DT":
                    htc = new HtmlTableCell();
                    //htc.VAlign = "middle"; // Commented by srivatsan
                    htc.VAlign = "top";
                    //htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
                    htc.Attributes.Add("Class", GetHtmlTableCellClassName(dsInput));
                    lblObj.ID = "lb_" + strCtrlId;
                    lblObj.Text = strCtrlDesc + strBr;
                    setLabelFont(ref lblObj);
                    if (dsInput != null)
                    {
                        lblObj.Visible = false;
                    }
                    //lblObj.Width = intLabelSize;
                    //htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
                    htc.Attributes.Add("Class", GetHtmlTableCellClassName(dsInput));
                    //htc.Controls.Add(new LiteralControl(strCtrlDesc + strBr));
                    //C1WebDateEdit txtDTObj = new C1WebDateEdit();
                    TextBox txtDTObj = new TextBox();
                    txtDTObj.ID = strCtrlId;
                    if (HttpContext.Current.Request.QueryString["PK"] == null) // Added by srivatsan
                        txtDTObj.Text = strDefaultVal;
                    if (tooltip != "")
                        txtDTObj.ToolTip = tooltip;//implemented by sanal on 11 Mar 2008
                    if (strCtrlWidth != "")
                    {
                        txtDTObj.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
                    }
                    if (strActualCtrlId == GlobalValues.CreatedDate)
                    {
                        txtDTObj.Text = DateTime.Now.ToString();
                        txtDTObj.Enabled = false;
                    }
                    else if (strActualCtrlId == GlobalValues.ModifiedDate)
                    {
                        txtDTObj.Enabled = false;
                    }

                    if (blnCaption)
                    {
                        htc.Controls.Add(lblObj);
                    }

                    if (!IsEdit) txtDTObj.Enabled = false;

                    if (strPageView == "2")
                    {
                        arlHtmlCells.Add(htc);
                        htc = new HtmlTableCell();
                    }
                    con = (Control)txtDTObj;
                    SetValuesforTransactionDocument("DT", dsInput, drTotals, ref sBindText, frmtotals, strActualCtrlId, ref con, intCurrentRow, ref strBindRowID, droTemp);

                    txtDTObj.CssClass = "controlFont controlWidth";
                    htc.Controls.Add(txtDTObj);
                    //loadDateTimeScript(droTemp, ref htc, txtDTObj.ID, ref DateTimestring);
                    addDateIfDateTime(droTemp, ref htc, txtDTObj.ID);
                    ///
                    if (IsKey == "true")
                    {
                        txtDTObj.BorderColor = cKey;
                        if (HttpContext.Current.Request.QueryString.Get("CPY") == null && HttpContext.Current.Request.QueryString.Get("PK") != null && !IsMutipleRecordPage)
                        {
                            txtDTObj.Enabled = false;
                        }
                        /*Label lblKey = new Label();
                        lblKey.ForeColor = System.Drawing.Color.Red;
                        lblKey.Text = "*";
                        htc.Controls.Add(lblKey);*/
                        //addMandatoryValidator(ref htc, txtDTObj);
                    }
                    if (IsPrimary == "true")
                    {
                        if (dsInput == null)
                        {
                            addMandatoryValidator(ref htc, txtDTObj);
                        }
                    }
                    arlHtmlCells.Add(htc);
                    break;
                case "PW":
                case "ENC":
                    htc = new HtmlTableCell();
                    //htc.VAlign = "middle"; // Commented by srivatsan on Mar 19 2009
                    htc.VAlign = "top";


                    //htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
                    htc.Attributes.Add("Class", GetHtmlTableCellClassName(dsInput));
                    //htc.Controls.Add(new LiteralControl(strCtrlDesc + strBr));
                    lblObj.ID = "lb_" + strCtrlId;
                    lblObj.Text = strCtrlDesc + strBr;
                    setLabelFont(ref lblObj);
                    if (dsInput != null)
                    {
                        lblObj.Visible = false;
                    }
                    ////lblObj.Width = intLabelSize;
                    txtObj = new TextBox();
                    //txtObj.TextMode = TextBoxMode.Password;
                    txtObj.ID = strCtrlId;
                    if (HttpContext.Current.Request.QueryString["PK"] == null) // Added by srivatsan
                        txtObj.Text = strDefaultVal;
                    if (tooltip != "")
                        txtObj.ToolTip = tooltip;//implemented by sanal on 11 Mar 2008
                    if (strCtrlWidth != "")
                    {
                        txtObj.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
                    }
                    if (strActualCtrlId == GlobalValues.CreatedDate)
                    {
                        txtObj.Text = DateTime.Now.ToString();
                        txtObj.Enabled = false;
                    }
                    else if (strActualCtrlId == GlobalValues.ModifiedDate)
                    {
                        txtObj.Enabled = false;
                    }

                    if (Attrib_Size != "")
                        txtObj.MaxLength = Convert.ToInt32(Attrib_Size);

                    if (blnSeqControl)
                    {
                        txtObj.Text = intCurrentRow.ToString();
                    }

                    con = (Control)txtObj;
                    SetValuesforTransactionDocument("PW", dsInput, drTotals, ref sBindText, frmtotals, strActualCtrlId, ref con, intCurrentRow, ref strBindRowID, droTemp);

                    txtObj.Attributes.Add("class", "controlFont controlWidth");
                    //txtObj.Attributes.Add("style","text-align:right");
                    //if (droTemp["control_attrib_type"].ToString() == "NU" || droTemp["control_attrib_type"].ToString() == "DC" || droTemp["control_attrib_type"].ToString() == "CU")
                    //    txtObj.Attributes["dir"] = "rtl";

                    if (!IsEdit) txtObj.Enabled = false;
                    if (blnCaption)
                    {
                        htc.Controls.Add(lblObj);
                    }
                    if (strPageView == "2")
                    {
                        arlHtmlCells.Add(htc);
                        htc = new HtmlTableCell();
                    }
                    htc.Controls.Add(txtObj);
                    if (strCtrlHtml.ToUpper() == "PW") // Added by 'Imran Gani' on 10-Jul-2014, to handle encryption fields.
                    {
                        txtObj.TextMode = TextBoxMode.Password;
                        Literal l = new Literal();
                        l.Text = "&nbsp;<img src=\"Images/key.gif\" alt=\"Password Field\" border=\"0\" />";

                        HiddenField hfOrgPassword = new HiddenField();//added by sanal on Aug 08, 2011
                        hfOrgPassword.ID = "pwd_org_" + strCtrlId;
                        htc.Controls.Add(hfOrgPassword);

                        htc.Controls.Add(l);
                    }
                    //loadDateTimeScript(droTemp, ref htc, txtObj.ID,ref DateTimestring);
                    addDateIfDateTime(droTemp, ref htc, txtObj.ID);
                    ///
                    if (strBindRowID != "")//sanal
                    {
                        htc.Controls.Add(getBindDIV(txtObj.ID, strBindRowID, null, true));
                        htc.Controls.Add(getBindNewLink(strBindRowID, null));
                        htc.Style.Add("white-space", "nowrap");
                    }
                    if (IsKey == "true")
                    {
                        txtObj.BorderColor = cKey;
                        if (HttpContext.Current.Request.QueryString.Get("CPY") == null && HttpContext.Current.Request.QueryString.Get("PK") != null && !IsMutipleRecordPage)
                        {
                            txtObj.Enabled = false;
                        }
                        /*Label lblKey = new Label();
                        lblKey.ForeColor = System.Drawing.Color.Red;
                        lblKey.Text = "*";
                        htc.Controls.Add(lblKey);*/
                        //addMandatoryValidator(ref htc, txtObj);
                    }
                    if (IsPrimary == "true")
                    {
                        if (dsInput == null)
                        {
                            addMandatoryValidator(ref htc, txtObj);
                        }
                    }
                    if (inputMask != "") processInputMask(ref htc, txtObj, inputMask);
                    arlHtmlCells.Add(htc);
                    break;
                case "DL": // Added by 'Imran Gani' on 26-Dec-2013, for droplist support.
                    htc = new HtmlTableCell();
                    //htc.VAlign = "middle";
                    htc.VAlign = "top";
                    //htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
                    htc.Attributes.Add("Class", GetHtmlTableCellClassName(dsInput));
                    lblObj.ID = "lb_" + strCtrlId;
                    lblObj.Text = strCtrlDesc + strBr;
                    setLabelFont(ref lblObj);
                    if (dsInput != null)
                        lblObj.Visible = false;
                    //lblObj.Width = intLabelSize;
                    //htc.Controls.Add(new LiteralControl(strCtrlDesc + strBr));
                    DropDownList DDL_Droplist = new DropDownList();
                    DDL_Droplist.ID = strCtrlId;
                    if (tooltip != "")
                        DDL_Droplist.ToolTip = tooltip;
                    if (strCtrlWidth != "")
                        DDL_Droplist.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));

                    HDDatabase hd = new HDDatabase();
                    DataTable dt_Droplist = hd.GetDataTable("select * from [sy_pg_ctr_droplist] where [page_id] = '" + droTemp["page_id"].ToString() + "' and [control_id] = '" + droTemp["af_row_id"].ToString() + "';");
                    foreach (DataRow dr in dt_Droplist.Select("droplist_value in ('none','empty')"))
                        dr["droplist_value"] = "";
                    DDL_Droplist.DataSource = dt_Droplist;
                    DDL_Droplist.DataTextField = "droplist_value";
                    DDL_Droplist.DataValueField = "droplist_value";
                    DDL_Droplist.DataBind();
                    #region New code Added by 'Imran Gani' on 19-Mar-2014, to use switch case with MBLocale
                    //foreach (DataRow dr in dt_Droplist.Rows) // Added by 'Imran Gani' on 19-Mar-2014, for MBLocale
                    //{
                    //    string sDLText = dr["droplist_value"].ToString();
                    //    try
                    //    {
                    //        switch (droTemp["control_attrib_type"].ToString().ToLower())
                    //        {
                    //            case "dt":
                    //            case "da":
                    //                sDLText = MBLocalization.getLocalizedDate(HttpContext.Current.Session["userlocale"].ToString(), DateTime.Parse(dr["droplist_value"].ToString()));
                    //                break;
                    //            case "nu":
                    //            case "an":
                    //                sDLText = MBLocalization.getLocalizedInteger(HttpContext.Current.Session["userlocale"].ToString(), int.Parse(dr["droplist_value"].ToString()));
                    //                break;
                    //            case "cu":
                    //            case "dc":
                    //            case "fl":
                    //                sDLText = MBLocalization.getLocalizedDecimal(HttpContext.Current.Session["userlocale"].ToString(), double.Parse(dr["droplist_value"].ToString()));
                    //                break;
                    //        }
                    //    }
                    //    catch (Exception ex)
                    //    {
                    //        sDLText = dr["droplist_value"].ToString();
                    //        dr["droplist_value"] = new Localization().getDBValueFromLocale(dr["droplist_value"].ToString(), droTemp["control_attrib_type"].ToString());
                    //    }
                    //    DDL_Droplist.Items.Add(new ListItem(sDLText, dr["droplist_value"].ToString()));
                    //}
                    #endregion
                    if (HttpContext.Current.Request.QueryString["PK"] == null)
                        if (strDefaultVal != "")
                            DDL_Droplist.Items.FindByText(strDefaultVal).Selected = true;

                    con = (Control)DDL_Droplist;
                    SetValuesforTransactionDocument("DD", dsInput, drTotals, ref sBindText, frmtotals, strActualCtrlId, ref con, intCurrentRow, ref strBindRowID, droTemp);

                    if (blnCaption)
                        htc.Controls.Add(lblObj);

                    if (!IsEdit) DDL_Droplist.Enabled = false;

                    if (strPageView == "2")
                    {
                        arlHtmlCells.Add(htc);
                        htc = new HtmlTableCell();
                    }
                    DDL_Droplist.CssClass = "controlFont controlWidth";
                    SetDefaultValueForOwnerID(ref DDL_Droplist, strActualCtrlId);
                    htc.Controls.Add(DDL_Droplist);

                    if (IsKey == "true")
                    {
                        DDL_Droplist.BorderColor = cKey;
                        if (HttpContext.Current.Request.QueryString.Get("CPY") == null && HttpContext.Current.Request.QueryString.Get("PK") != null && !IsMutipleRecordPage)
                        {
                            DDL_Droplist.Enabled = false;
                        }
                        /*Label lblKey = new Label();
                        lblKey.ForeColor = System.Drawing.Color.Red;
                        lblKey.Text = "*";
                        htc.Controls.Add(lblKey);*/
                        //addMandatoryValidator(ref htc, DDL);
                    }
                    if (IsPrimary == "true")
                        if (dsInput == null)
                            addMandatoryValidator(ref htc, DDL_Droplist);
                    htc.VAlign = "Top";
                    arlHtmlCells.Add(htc);
                    break;
                default:
                    htc = new HtmlTableCell();
                    htc.VAlign = "top";
                   // htc.Attributes.Add("class", "Dynamic_HtmlTableCell");
                    htc.Attributes.Add("Class", GetHtmlTableCellClassName(dsInput));
                    //htc.Controls.Add(new LiteralControl(strCtrlDesc + strBr));
                    lblObj.ID = "lb_" + strCtrlId;
                    lblObj.Text = strCtrlDesc + strBr;
                    setLabelFont(ref lblObj);
                    if (dsInput != null)
                    {
                        lblObj.Visible = false;
                    }
                    lblObj.Font.Bold = true;
                    ////lblObj.Width = intLabelSize;
                    Label txtObj1 = new Label();
                    txtObj1.ID = strCtrlId;
                    if (HttpContext.Current.Request.QueryString["PK"] == null) // Added by srivatsan
                        txtObj1.Text = strDefaultVal;
                    
                    con = (Control)txtObj1;
                    SetValuesforTransactionDocument("", dsInput, drTotals, ref sBindText, frmtotals, strActualCtrlId, ref con, intCurrentRow, ref strBindRowID, droTemp);

                    if (tooltip != "")
                        txtObj1.ToolTip = tooltip;//implemented by sanal on 11 Mar 2008
                    if (strCtrlWidth != "")
                    {
                        txtObj1.Width = Unit.Pixel(Convert.ToInt32(strCtrlWidth));
                    }
                    if (strActualCtrlId == GlobalValues.CreatedDate)
                    {
                        txtObj1.Text = DateTime.Now.ToString();
                        txtObj1.Enabled = false;
                    }
                    else if (strActualCtrlId == GlobalValues.ModifiedDate)
                    {
                        txtObj1.Enabled = false;
                    }

                    if (blnSeqControl)
                    {
                        txtObj1.Text = intCurrentRow.ToString();
                    }
                    if (blnCaption)
                    {
                        htc.Controls.Add(lblObj);
                    }
                    if (strPageView == "2")
                    {
                        arlHtmlCells.Add(htc);
                        htc = new HtmlTableCell();
                    }
                    txtObj1.CssClass = "controlFont controlWidth";
                    htc.Controls.Add(txtObj1);
                    arlHtmlCells.Add(htc);
                    break;
            }
        }
        dtBind = null;
        return arlHtmlCells;

    }
    private bool keepPasswordAsText()
    {
        bool ret = false;
        try
        {
            ret = true;
        }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error in keepPasswordAsText: " + e.Message);
        }
        return ret;
    }
    public void SetValuesforTransactionDocument(string controlhtml, DataSet dsInput, DataRow[] drTotals, ref string sbindtext, HtmlForm frmtotals, string strActualCtrlId, ref Control conobj, int intCurrentRow, ref string strBindRowID, DataRow droTemp)
    {
        BindControl BC = new BindControl();
        //if (drTotals != null)
        //{
        //    if (drTotals.Length > 0)
        //    {
        //        for (int i = 0; i < drTotals.Length; i++)
        //        {
        //            if (drTotals[i]["attrib_id"].ToString().ToLower() == strActualCtrlId.ToLower())
        //            {
        //                // txtObj.AutoPostBack = true;
        //                // txtObj.TextChanged += new EventHandler(txtObj_TextChanged);
        //            }

        //        }
        //    }
        //}

        switch(controlhtml.ToUpper())
        {
            case "TB":
            // Added by srivatsan on May 07 2009
            if (!frmtotals.Page.IsPostBack)
            {
                if (dsInput != null)
                {
                    if (dsInput.Tables.Count > 0)
                    {
                        if (dsInput.Tables[0].Rows.Count > 0)
                        {
                            try
                            {
                                if (conobj is TextBox)
                                {
                                    TextBox txtObj = (TextBox)conobj;
                                    //txtObj.Text = dsInput.Tables[0].Rows[intCurrentRow - 1][strActualCtrlId].ToString();
                                    #region New code Added by 'Imran Gani' on 28-Feb-2014, to use switch case with MBLocale
                                    string strCtrlValue = dsInput.Tables[0].Rows[intCurrentRow - 1][strActualCtrlId].ToString();
                                    switch (droTemp["control_attrib_type"].ToString().ToLower())
                                    {
                                        case "da":
                                            if (strCtrlValue != "")
                                                txtObj.Text = MBLocalization.getLocalizedDate(HttpContext.Current.Session["userlocale"].ToString(), DateTime.Parse(strCtrlValue));
                                            break;
                                        case "dt":
                                            if (strCtrlValue != "")
                                                txtObj.Text = MBLocalization.getLocalizedDateTime(HttpContext.Current.Session["userlocale"].ToString(), DateTime.Parse(strCtrlValue));
                                            break;
                                        case "cu":
                                        case "dc":
                                        case "fl":
                                            if (strCtrlValue != "")
                                                txtObj.Text = MBLocalization.getLocalizedDecimal(HttpContext.Current.Session["userlocale"].ToString(), Convert.ToDouble(strCtrlValue));
                                            break;
                                        case "nu":
                                        case "an":
                                            if (strCtrlValue != "")
                                                txtObj.Text = MBLocalization.getLocalizedInteger(HttpContext.Current.Session["userlocale"].ToString(), Convert.ToInt32(strCtrlValue));
                                            break;
                                    }
                                    #endregion
                                    if (strBindRowID != "")
                                    {
                                        HDDatabase HDD = new HDDatabase();
                                        string sql = BC.GetBindSql(strBindRowID);
                                        DataSet dsbinddata = HDD.GetDataset(sql);
                                        if (dsbinddata != null)
                                        {
                                            if (dsbinddata.Tables.Count > 0)
                                            {
                                                if (dsbinddata.Tables[0].Rows.Count > 0)
                                                {
                                                    BC.HandleLocalizedBindText(dsbinddata.Tables[0], strBindRowID);
                                                    //string bindval = dsbinddata.Tables[0].Rows[0][""]
                                                    DataRow[] drr = dsbinddata.Tables[0].Select("val = '" + txtObj.Text + "'");
                                                    if (drr.Length > 0)
                                                    {
                                                        txtObj.Text = drr[0]["fld"].ToString();
                                                        sbindtext = drr[0]["val"].ToString();
                                                    }
                                                }
                                            }
                                        }


                                    }
                                }
                            }
                            catch { }
                        }
                    }
                }
            }
            break;
            case "TA":
                // Added by srivatsan on May 07 2009
                if (!frmtotals.Page.IsPostBack)
                {
                    if (dsInput != null)
                    {
                        if (dsInput.Tables.Count > 0)
                        {
                            if (dsInput.Tables[0].Rows.Count > 0)
                            {
                                try
                                {
                                    if (conobj is TextBox)
                                    {
                                        TextBox txtObj = (TextBox)conobj;
                                        txtObj.Text = dsInput.Tables[0].Rows[intCurrentRow - 1][strActualCtrlId].ToString();
                                    }
                                }
                                catch { }
                            }
                        }
                    }
                }
                //
                break;
            case"CB":
                // Added by srivatsan on May 07 2009
                if (!frmtotals.Page.IsPostBack)
                {
                    if (dsInput != null)
                    {
                        if (dsInput.Tables.Count > 0)
                        {
                            if (dsInput.Tables[0].Rows.Count > 0)
                            {
                                try
                                {
                                    if (conobj is CheckBox)
                                    {
                                        CheckBox CB = (CheckBox)conobj;
                                        CB.Checked = dsInput.Tables[0].Rows[intCurrentRow - 1][strActualCtrlId].ToString().ToLower() == "true" ? true : false;
                                    }
                                }
                                catch { }
                            }
                        }
                    }
                }
                //
                break;
            case"DD":
                // Added by srivatsan on May 07 2009
                if (!frmtotals.Page.IsPostBack)
                {
                    if (dsInput != null)
                    {
                        if (dsInput.Tables.Count > 0)
                        {
                            if (dsInput.Tables[0].Rows.Count > 0)
                            {
                                try
                                {
                                    if (conobj is DropDownList)
                                    {
                                        DropDownList DDL = (DropDownList)conobj;
                                        DDL.SelectedValue = dsInput.Tables[0].Rows[intCurrentRow - 1][strActualCtrlId].ToString();
                                    }
                                }
                                catch { }
                            }
                        }
                    }
                }
                //
                break;
            case "DL": // Added by 'Imran Gani' on 26-Dec-2013, for droplist support.
                if (!frmtotals.Page.IsPostBack)
                    if (dsInput != null)
                        if (dsInput.Tables.Count > 0)
                            if (dsInput.Tables[0].Rows.Count > 0)
                            {
                                try
                                {
                                    if (conobj is DropDownList)
                                    {
                                        DropDownList DDL = (DropDownList)conobj;
                                        DDL.SelectedValue = dsInput.Tables[0].Rows[intCurrentRow - 1][strActualCtrlId].ToString();
                                    }
                                }
                                catch { }
                            }
                break;
            case"DA":
                // Added by srivatsan on May 07 2009
                if (!frmtotals.Page.IsPostBack)
                {
                    if (dsInput != null)
                    {
                        if (dsInput.Tables.Count > 0)
                        {
                            if (dsInput.Tables[0].Rows.Count > 0)
                            {
                                try
                                {
                                    if (conobj is TextBox)
                                    {
                                        TextBox txtDAObj = (TextBox)conobj;
                                        txtDAObj.Text = dsInput.Tables[0].Rows[intCurrentRow - 1][strActualCtrlId].ToString();
                                    }
                                }
                                catch { }
                            }
                        }
                    }
                }
                //
                break;
            case "DT":
                // Added by srivatsan on May 07 2009
                if (!frmtotals.Page.IsPostBack)
                {
                    if (dsInput != null)
                    {
                        if (dsInput.Tables.Count > 0)
                        {
                            if (dsInput.Tables[0].Rows.Count > 0)
                            {
                                try
                                {
                                    if (conobj is TextBox)
                                    {
                                        TextBox txtDTObj = (TextBox)conobj;
                                        txtDTObj.Text = dsInput.Tables[0].Rows[intCurrentRow - 1][strActualCtrlId].ToString();
                                    }
                                }
                                catch { }
                            }
                        }
                    }
                }
                //
                break;
            case"PW":
                // Added by srivatsan on May 07 2009
                if (!frmtotals.Page.IsPostBack)
                {
                    if (dsInput != null)
                    {
                        if (dsInput.Tables.Count > 0)
                        {
                            if (dsInput.Tables[0].Rows.Count > 0)
                            {
                                try
                                {
                                    if (conobj is TextBox)
                                    {
                                        TextBox txtObj = (TextBox)conobj;
                                        txtObj.Text = dsInput.Tables[0].Rows[intCurrentRow - 1][strActualCtrlId].ToString();
                                    }
                                }
                                catch { }
                            }
                        }
                    }
                }
            //
                break;
            case"":
                // Added by srivatsan on May 07 2009
                if (!frmtotals.Page.IsPostBack)
                {
                    if (dsInput != null)
                    {
                        if (dsInput.Tables.Count > 0)
                        {
                            try
                            {
                                if (conobj is Label)
                                {
                                    Label txtObj1 = (Label)conobj;
                                    txtObj1.Text = dsInput.Tables[0].Rows[intCurrentRow - 1][strActualCtrlId].ToString();
                                }
                                else if (conobj is HiddenField)
                                {
                                    HiddenField hfobj = (HiddenField)conobj;
                                    hfobj.Value = dsInput.Tables[0].Rows[intCurrentRow - 1][strActualCtrlId].ToString();
                                }
                                else if (conobj is TextBox)
                                {
                                    TextBox txtobj = (TextBox)conobj;
                                    txtobj.Text = dsInput.Tables[0].Rows[intCurrentRow - 1][strActualCtrlId].ToString();
                                }
                            }
                            catch { }
                        }
                    }
                }
                //
                break;

                break;
            default:
                
                break;
        

    }
    }

    private void setLabelFont(ref Label lbl)//created by sanal on 05 apr 2008
    {
        //lbl.Font.Name = "Arial";
        //lbl.Font.Size = FontUnit.Small;
        //lbl.CssClass = "controlFont"; //Commented by srivatsan
        lbl.CssClass = "controlLabelFont";
    }
    public void provideEmailValidation(ref HtmlTableCell htc, Control ctrl, string strctrlid, string afrowid)//sanal on Nov 04, 2009
    {
        //return;
        if (ctrl != null && htc != null)
        {
            if (ctrl is TextBox)
            {
                Literal lReq = new Literal();
                lReq.ID = "email_" + ctrl.ID;
                if (UseMaxBloxEmailCompose()) // Added by 'Imran Gani' on 21-Nov-12, for edit page.
                {
                    string navurl = "ComposeEmail.aspx?pgs_id=" + HttpContext.Current.Request.QueryString["pgs_id"].ToString() + "&mn=" + HttpContext.Current.Request.QueryString["mn"].ToString() + "&PK=" + afrowid + "&CnID=" + strctrlid + "";
                    //if (afrowid.Trim() != "")
                    //    navurl = navurl + "&MK=" + afrowid + "";
                    lReq.Text = "&nbsp;<img src=\"Images/email.gif\" alt=\"Send E-mail\" onclick=\"javascript:handleEmailField('ctl00_ContentPlaceHolder3_" + ctrl.ID + "',true,'" + navurl + "');\" onMouseOut=\"javascript:this.src='images/email.gif'\" onmouseover=\"javascript:this.src='images/email-hover.gif'\" style=\"cursor:pointer;vertical-align:middle;\"></img>";
                }
                else
                    lReq.Text = @"&nbsp;<img onMouseOut=""javascript:this.src='images/email.gif'"" onmouseover=""javascript:this.src='images/email-hover.gif'"" src=""Images/email.gif"" style=""cursor:pointer;vertical-align:middle;"" alt=""Send E-mail"" onClick=""javascript:handleEmail('" + "ctl00_ContentPlaceHolder3_" + ctrl.ID + @"');""></img>";
                htc.Controls.Add(lReq);

                //validate email
                RegularExpressionValidator rev = new RegularExpressionValidator();
                rev.ID = "rev_em_" + ctrl.ID;
                rev.ErrorMessage = "Invalid E-mail";
                rev.Display = ValidatorDisplay.None;
                rev.ValidationExpression = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";//email
                rev.ControlToValidate = ctrl.ID;
                htc.Controls.Add(rev);

                //include extender
                ValidatorCalloutExtender vce = new ValidatorCalloutExtender();
                vce.TargetControlID = rev.ID;
                vce.WarningIconImageUrl = "Images/warning_small.gif";
                vce.ID = "vce_rev_em_" + ctrl.ID;
                vce.HighlightCssClass = "maskInvalid";
                htc.Controls.Add(vce);
            }
        }
    }

    public void provideEmailValidation(ref HtmlTableCell htc, Control ctrl, string strctrlid, DataRow drtemp, string afrowid, DataTable dtaPageKeys, string strpageid)//DataRow drTemp,string page_id,int currrow)//sanal on Nov 04, 2009
    {
        //return;
        char[] MyChar = { 'p', '_' };
        string NewString = strpageid.TrimStart(MyChar);//added by Bala Nov 30,2011-get page id
        if (ctrl != null && htc != null)
        {
            if (ctrl is TextBox)
            {
                string strPagesetRowId = "";
                string masterobj = "";
                string masterdisplayfield = "";
                if (drtemp != null)
                    if (NewString != null)
                    {
                        //DataSet ds = drtemp.Table.DataSet;// comments by Bala Nov 
                        //if (ds.Tables["PageSet"] != null)
                        //{
                        //if (ds.Tables["PageSet"].Rows.Count > 0)
                        //strPagesetRowId = ds.Tables["PageSet"].Rows[0]["pageset_id"].ToString(); 
                        strPagesetRowId = NewString;
                        if (dtaPageKeys != null)
                            if (dtaPageKeys.Rows.Count > 0)
                            {
                                masterdisplayfield = dtaPageKeys.Rows[0]["display_att"].ToString();
                                masterobj = dtaPageKeys.Rows[0]["master_obj"].ToString();
                            }

                        //if (HttpContext.Current.Request.QueryString["PK"] != null && HttpContext.Current.Request.QueryString["CPY"]==null)
                        if (HttpContext.Current.Request.QueryString["Vmode"] != null)
                        {
                            Literal lReq = new Literal();
                            lReq.ID = "email_" + ctrl.ID;
                            //CommonFunctions cf = new CommonFunctions();
                            if (UseMaxBloxEmailCompose())
                            {
                                string navurl = "ComposeEmail.aspx?pgs_id=" + strPagesetRowId + "&mn=" + HttpContext.Current.Request.QueryString["mn"].ToString() + "&PK=" + HttpContext.Current.Request.QueryString["PK"].ToString() + "&CnID=" + strctrlid + "";
                                if (afrowid.Trim() != "")
                                    navurl = navurl + "&MK=" + afrowid + "";
                                //if (HttpContext.Current.Request.QueryString["MK"] != null)
                                //{
                                //    navurl = navurl + "&MK=" + HttpContext.Current.Request.QueryString["MK"].ToString() + "|"+masterobj+"|"+masterdisplayfield+"";
                                //}
                                lReq.Text = "&nbsp;<img src=\"Images/email.gif\" alt=\"Send E-mail\" onclick=\"javascript:handleEmailField('ctl00_ContentPlaceHolder3_" + ctrl.ID + "',true,'" + navurl + "');\" onMouseOut=\"javascript:this.src='images/email.gif'\" onmouseover=\"javascript:this.src='images/email-hover.gif'\" style=\"cursor:pointer;vertical-align:middle;\"></img>";
                                //lReq.Text = "&nbsp;<img src=\"Images/email.gif\" alt=\"Send E-mail\" onclick=\"javascript:window.location.href('" + navurl + "')\" onMouseOut=\"javascript:this.src='images/email.gif'\" onmouseover=\"javascript:this.src='images/email-hover.gif'\" style=\"cursor:pointer;vertical-align:middle;\"></img>";
                            }
                            else
                                lReq.Text = @"&nbsp;<img onMouseOut=""javascript:this.src='images/email.gif'"" onmouseover=""javascript:this.src='images/email-hover.gif'"" src=""Images/email.gif"" style=""cursor:pointer;vertical-align:middle;"" alt=""Send E-mail"" onClick=""javascript:handleEmail('" + "ctl00_ContentPlaceHolder3_" + ctrl.ID + @"');""></img>";
                            //cf = null;
                            htc.Controls.Add(lReq);
                        }
                        #region Bala
                        //-----added by Bala Nov 30,2011; for showing logo in the edit
                        else if (HttpContext.Current.Request.QueryString["PK"] != null && HttpContext.Current.Request.QueryString["VMODE"] == null)
                        {
                            if (HttpContext.Current.Request.QueryString["CPY"] == null)
                            {
                                Literal lReq = new Literal();
                                lReq.ID = "email_" + ctrl.ID;
                                if (UseMaxBloxEmailCompose()) // Added by 'Imran Gani' on 21-Nov-12, for edit page.
                                {
                                    string navurl = "ComposeEmail.aspx?pgs_id=" + strPagesetRowId + "&mn=" + HttpContext.Current.Request.QueryString["mn"].ToString() + "&PK=" + HttpContext.Current.Request.QueryString["PK"].ToString() + "&CnID=" + strctrlid + "";
                                    if (afrowid.Trim() != "")
                                        navurl = navurl + "&MK=" + afrowid + "";
                                    lReq.Text = "&nbsp;<img src=\"Images/email.gif\" alt=\"Send E-mail\" onclick=\"javascript:handleEmailField('ctl00_ContentPlaceHolder3_" + ctrl.ID + "',true,'" + navurl + "');\" onMouseOut=\"javascript:this.src='images/email.gif'\" onmouseover=\"javascript:this.src='images/email-hover.gif'\" style=\"cursor:pointer;vertical-align:middle;\"></img>";
                                }
                                else
                                    lReq.Text = @"&nbsp;<img onMouseOut=""javascript:this.src='images/email.gif'"" onmouseover=""javascript:this.src='images/email-hover.gif'"" src=""Images/email.gif"" style=""cursor:pointer;vertical-align:middle;"" alt=""Send E-mail"" onClick=""javascript:handleEmail('" + "ctl00_ContentPlaceHolder3_" + ctrl.ID + @"');""></img>";
                                htc.Controls.Add(lReq);
                            }
                        }
                        #endregion

                        //validate email
                        RegularExpressionValidator rev = new RegularExpressionValidator();
                        rev.ID = "rev_em_" + ctrl.ID;
                        rev.ErrorMessage = "Invalid E-mail";
                        rev.Display = ValidatorDisplay.None;
                        rev.ValidationExpression = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";//email
                        rev.ControlToValidate = ctrl.ID;
                        htc.Controls.Add(rev);

                        //include extender
                        ValidatorCalloutExtender vce = new ValidatorCalloutExtender();
                        vce.TargetControlID = rev.ID;
                        vce.WarningIconImageUrl = "Images/warning_small.gif";
                        vce.ID = "vce_rev_em_" + ctrl.ID;
                        vce.HighlightCssClass = "maskInvalid";
                        htc.Controls.Add(vce);
                        //}
                    }
            }
        }
    }

    //old function commented by Bala for email icon show
    //public void provideEmailValidation(ref HtmlTableCell htc, Control ctrl,string strctrlid,DataRow drtemp,string afrowid)//DataRow drTemp,string page_id,int currrow)//sanal on Nov 04, 2009
    //{
    //    //return;
    //    if (ctrl != null && htc != null)
    //    {
    //        if (ctrl is TextBox)
    //        {
    //            string strPagesetRowId = "";
    //            string masterobj = "";
    //            string masterdisplayfield = "";
    //            if(drtemp!=null)
    //                if (drtemp.Table.DataSet != null)
    //                {
    //                    DataSet ds = drtemp.Table.DataSet;
    //                    if (ds.Tables["PageSet"] != null)
    //                    {
    //                        if (ds.Tables["PageSet"].Rows.Count > 0)
    //                            strPagesetRowId = ds.Tables["PageSet"].Rows[0]["pageset_id"].ToString();

    //                        if (ds.Tables["PageKeys"] != null)
    //                            if (ds.Tables["PageKeys"].Rows.Count > 0)
    //                            {
    //                                masterdisplayfield = ds.Tables["PageKeys"].Rows[0]["display_att"].ToString();
    //                                masterobj = ds.Tables["PageKeys"].Rows[0]["master_obj"].ToString();
    //                            }

    //                        //if (HttpContext.Current.Request.QueryString["PK"] != null && HttpContext.Current.Request.QueryString["CPY"]==null)
    //                        if (HttpContext.Current.Request.QueryString["Vmode"] != null)
    //                        {
    //                            Literal lReq = new Literal();
    //                            lReq.ID = "email_" + ctrl.ID;
    //                            //CommonFunctions cf = new CommonFunctions();
    //                            if (UseMaxBloxEmailCompose())
    //                            {
    //                                string navurl = "ComposeEmail.aspx?pgs_id=" + strPagesetRowId + "&mn=" + HttpContext.Current.Request.QueryString["mn"].ToString() + "&PK=" + HttpContext.Current.Request.QueryString["PK"].ToString() + "&CnID=" + strctrlid + "";
    //                                if (afrowid.Trim() != "")
    //                                    navurl = navurl + "&MK=" + afrowid + "";
    //                                //if (HttpContext.Current.Request.QueryString["MK"] != null)
    //                                //{
    //                                //    navurl = navurl + "&MK=" + HttpContext.Current.Request.QueryString["MK"].ToString() + "|"+masterobj+"|"+masterdisplayfield+"";
    //                                //}
    //                                lReq.Text = "&nbsp;<img src=\"Images/email.gif\" alt=\"Send E-mail\" onclick=\"javascript:handleEmailField('ctl00_ContentPlaceHolder3_" + ctrl.ID + "',true,'" + navurl + "');\" onMouseOut=\"javascript:this.src='images/email.gif'\" onmouseover=\"javascript:this.src='images/email-hover.gif'\" style=\"cursor:pointer;vertical-align:middle;\"></img>";
    //                                //lReq.Text = "&nbsp;<img src=\"Images/email.gif\" alt=\"Send E-mail\" onclick=\"javascript:window.location.href('" + navurl + "')\" onMouseOut=\"javascript:this.src='images/email.gif'\" onmouseover=\"javascript:this.src='images/email-hover.gif'\" style=\"cursor:pointer;vertical-align:middle;\"></img>";
    //                            }
    //                            else
    //                                lReq.Text = @"&nbsp;<img onMouseOut=""javascript:this.src='images/email.gif'"" onmouseover=""javascript:this.src='images/email-hover.gif'"" src=""Images/email.gif"" style=""cursor:pointer;vertical-align:middle;"" alt=""Send E-mail"" onClick=""javascript:handleEmail('" + "ctl00_ContentPlaceHolder3_" + ctrl.ID + @"');""></img>";
    //                            //cf = null;
    //                            htc.Controls.Add(lReq);
    //                        }

    //                        //validate email
    //                        RegularExpressionValidator rev = new RegularExpressionValidator();
    //                        rev.ID = "rev_em_" + ctrl.ID;
    //                        rev.ErrorMessage = "Invalid E-mail";
    //                        rev.Display = ValidatorDisplay.None;
    //                        rev.ValidationExpression = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";//email
    //                        rev.ControlToValidate = ctrl.ID;
    //                        htc.Controls.Add(rev);

    //                        //include extender
    //                        ValidatorCalloutExtender vce = new ValidatorCalloutExtender();
    //                        vce.TargetControlID = rev.ID;
    //                        vce.WarningIconImageUrl = "Images/warning_small.gif";
    //                        vce.ID = "vce_rev_em_" + ctrl.ID;
    //                        vce.HighlightCssClass = "maskInvalid";
    //                        htc.Controls.Add(vce);
    //                    }
    //                }
    //        }
    //    }
    //}
    public void processInputMask(ref HtmlTableCell cc, Control ctrl,string maskId)//created by sanal on 14 Mar 2008
    {
        DataTable dt = new DataTable();
        try
        {
            //string constant = "ctl00_ContentPlaceHolder3_";            
            dt = _getMaskDetails(maskId);
            if (dt == null) return;
            if (dt.Rows.Count < 1) return;
            DataRow dr = dt.Rows[0];

            Literal ll = new Literal();
            ll.Text = "&nbsp;";

            cc.Controls.Add(ll);
            cc.Controls.Add(_getMaskEditValidator(dr, ctrl));
            cc.Controls.Add(_getMaskEditExtender(dr, ctrl));
            dt = null;
        }
        catch (Exception e)
        {
            dt = null;
            LogWriter.WriteLog("Error in processInputMask: " + e.Message);
        }
    }
    private MaskedEditExtender _getMaskEditExtender(DataRow dr, Control ctrl)//created by sanal on 14 Mar 2008
    {
        //adds the extender control with properties
        MaskedEditExtender mex = new MaskedEditExtender();
        mex.ID = "mex_" + ctrl.ID;
        mex.MaskType = getMaskType(dr["type"].ToString());
        mex.TargetControlID = ctrl.ID;
        mex.ErrorTooltipEnabled = true;
        mex.Enabled = true;
        mex.EnableViewState = true;
        mex.Mask = dr["mask_string"].ToString();
        mex.PromptCharacter = dr["prompt_character"].ToString();
        mex.AcceptNegative = getMaskEditSymbol(dr["accept_negative"].ToString());
        mex.AutoComplete = dr["auto_complete"].ToString() == "" ? false : Convert.ToBoolean(dr["auto_complete"].ToString());
        mex.MessageValidatorTip = dr["message_validator_tip"].ToString() == "" ? false : Convert.ToBoolean(dr["message_validator_tip"].ToString());
        mex.OnInvalidCssClass = "maskInvalid";
        mex.ClearMaskOnLostFocus = dr["clear_mask_blur"].ToString() == "" ? true : Convert.ToBoolean(dr["clear_mask_blur"].ToString()); 
        //mex.ClearTextOnInvalid = true;
        return mex;
    }
    private MaskedEditValidator _getMaskEditValidator(DataRow dr, Control ctrl)//created by sanal on 14 Mar 2008
    {
        //adds the validator control with properties
        MaskedEditValidator mev = new MaskedEditValidator();
        mev.ID = "mev_" + ctrl.ID;
        mev.ControlExtender = "mex_" + ctrl.ID;
        if (dr["tooltip_message"].ToString() != "") mev.TooltipMessage = dr["tooltip_message"].ToString();
        mev.ControlToValidate = ctrl.ID;
        mev.SetFocusOnError = true;
        mev.Display = ValidatorDisplay.Static;
        //mev.ErrorMessage = "Error Message";
        mev.EnableClientScript = true;
        mev.Enabled = true;
        mev.EnableTheming = true;
        mev.EnableViewState = true;
        mev.IsValidEmpty = dr["is_valid_empty"].ToString() == "" ? false : Convert.ToBoolean(dr["is_valid_empty"].ToString());
        mev.SetFocusOnError = false;
        if (dr["maximum_value"].ToString() != "") mev.MaximumValue = dr["maximum_value"].ToString();
        if (dr["maximum_value_message"].ToString() != "") mev.MaximumValueMessage = dr["maximum_value_message"].ToString();
        if (dr["maximum_value_blurred_message"].ToString() != "") mev.MaximumValueBlurredMessage = dr["maximum_value_blurred_message"].ToString();
        if (dr["minimum_value"].ToString() != "") mev.MinimumValue = dr["minimum_value"].ToString();
        if (dr["minimum_value_message"].ToString() != "") mev.MinimumValueMessage = dr["minimum_value_message"].ToString();
        if (dr["minimum_value_blurred_message"].ToString() != "") mev.MinimumValueBlurredText = dr["minimum_value_blurred_message"].ToString();
        if (dr["empty_value_message"].ToString() != "") mev.EmptyValueMessage = dr["empty_value_message"].ToString();
        if (dr["empty_value_blurred_message"].ToString() != "") mev.EmptyValueBlurredText = dr["empty_value_blurred_message"].ToString();
        if (dr["invalid_value_message"].ToString() != "") mev.InvalidValueMessage = dr["invalid_value_message"].ToString();
        if (dr["invalid_value_blurred_message"].ToString() != "") mev.InvalidValueBlurredMessage = dr["invalid_value_blurred_message"].ToString();
        if (dr.Table.Columns.Contains("validation_expression"))
            if (dr["validation_expression"].ToString() != "") mev.ValidationExpression = dr["validation_expression"].ToString();
        return mev;
    }
    private MaskedEditShowSymbol getMaskEditSymbol(string acceptNegative)//created by sanal on 14 Mar 2008
    {
        switch (acceptNegative.ToLower())
        {
            case "none":
            case "":
                return MaskedEditShowSymbol.None;
                break;
            case "left":
                return MaskedEditShowSymbol.Left;
                break;
            case "right":
                return MaskedEditShowSymbol.Right;
                break;
            default:
                return MaskedEditShowSymbol.None;
                break;
        }
    }
    private MaskedEditType getMaskType(string type)//created by sanal on 14 Mar 2008
    {
        switch (type.ToLower())
        {
            case "none":
            case "":
                return MaskedEditType.None;
                break;
            case "number":
                return MaskedEditType.Number;
                break;
            case "date":
                return MaskedEditType.Date;
                break;
            case "time":
                return MaskedEditType.Time;
                break;
            case "datetime":
                return MaskedEditType.DateTime;
                break;
            default:
                return MaskedEditType.None;
                break;
        }
        return MaskedEditType.None;
    }
    private DataTable _getMaskDetails(string maskId)//created by sanal on 14 Mar 2008
    {
        DataTable dtRet = new DataTable();
        HDDatabase hdd = new HDDatabase();
        dtRet = hdd.GetDataTable("Select * from sy_format_masks where af_row_id='" + maskId + "'");
        hdd = null;
        return dtRet;
    }
    private void getMenuidAndPagesetid(string objTable, ref string strMenuRowId, ref string strPagesetRowId,ref string pagesetName, HDDatabase hdd)
    {
        if (objTable.Trim().Length < 1) return;

        HDDatabase hd = null;
        try
        {
            if (hdd != null)
                hd = hdd;
            else
                hd = new HDDatabase();
            string temp = "";
            //DataTable dt = hd.GetDataTable("Select page_id from sy_pg where page_table_name='" + objTable.Replace("'","''") + "'");
            DataTable dt = hd.GetDataTable("Select object_id from sy_obj where object_table='" + objTable.Replace("'", "''") + "'");
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    temp = dt.Rows[0]["object_id"].ToString();
                    //check for object access
                    dt = hd.GetDataTable("Select [read] from sy_obj_acc where object_id='" + temp.Replace("'", "''") + "' and role_id='" + HttpContext.Current.Session["roleid"].ToString() + "'");
                    if (dt != null)
                    {
                        if (dt.Rows.Count > 0)
                        {
                            if (dt.Rows[0]["read"].ToString().ToLower() == "true")//check for object access
                            {
                                dt = hd.GetDataTable("Select pageset_id from sy_pgs_mem where object_id='" + temp.Replace("'", "''") + "'");
                                if (dt != null)
                                {
                                    if (dt.Rows.Count > 0)
                                    {
                                        temp = dt.Rows[0]["pageset_id"].ToString();
                                        dt = hd.GetDataTable("Select af_row_id, pageset_id, pageset_name from sy_pgs where af_row_id='" + temp.Replace("'", "''") + "'");
                                        if (dt != null)
                                        {
                                            if (dt.Rows.Count > 0)
                                            {
                                                strPagesetRowId = dt.Rows[0]["af_row_id"].ToString();
                                                pagesetName = dt.Rows[0]["pageset_name"].ToString();
                                                dt = hd.GetDataTable("Select af_row_id from sy_mnu where pageset_id='" + strPagesetRowId.Replace("'", "''") + "' and is_active=1");
                                                if (dt != null)
                                                {
                                                    if (dt.Rows.Count > 0)
                                                    {
                                                        temp = dt.Rows[0]["af_row_id"].ToString();
                                                        //check for access
                                                        dt = hd.GetDataTable("Select is_accessible from sy_rol_acc where role_id='" + HttpContext.Current.Session["roleid"].ToString() + "' and menu_id = '" + temp + "';");
                                                        if (dt != null)
                                                        {
                                                            if (dt.Rows.Count > 0)
                                                            {
                                                                if (dt.Rows[0]["is_accessible"].ToString().ToLower() == "true")
                                                                {
                                                                    strMenuRowId = temp;
                                                                    dt = null;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error in getMenuidAndPagesetid: " + e.Message);
        }
        finally
        {
            hd = null;
        }
    }
    private Literal getBindNewLink(string strBindRowID, DataTable dtBind)
    {
        string divContent = "";
        string menu = "";
        string strPagesetRowId = ""; string pagesetName = "";
        try
        {
            HDDatabase hdd = new HDDatabase();
            DataTable dt = hdd.GetDataTable("select * from sy_bnd where af_row_id = '" + strBindRowID + "';");
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    getMenuidAndPagesetid(dt.Rows[0]["bind_table"].ToString(), ref menu, ref strPagesetRowId,ref pagesetName, hdd);
                    if (menu.Trim().Length > 0 && strPagesetRowId.Trim().Length > 0)
                    {
                        divContent = "&nbsp;<a href='" + "displaygrid.aspx?pgs_id=" + strPagesetRowId + "&mn=" + menu +  "'><img class=\"SearchPopup\" src='Images/list.gif' border='0' alt='Click here for " + pagesetName +" page'></img></a>";
                        //divContent = "<a href='" + "displaygrid.aspx?pgs_id=" + strPagesetRowId + "&mn=" + menu + "'><img class=\"SearchPopup\" src='Images/list.gif' border='0' alt='Click here for " + pagesetName + " page'></img></a>";
                    }
                }
            }
            dt = null;
            hdd = null;           
            //divContent = "&nbsp;<a href='www.yahoo.com'><img src='Images/new.gif' border='0' alt='Create new Employee Master'></img></a>";
        }
        catch (Exception e)
        {
            divContent = "";
            LogWriter.WriteLog("Error in getBindNewLink: " + e.Message);
        }
        Literal ll = new Literal();
        //ll.ID = "ll_DIV_NewLink_" + strBindRowID;
        ll.Text = divContent;
        return ll;
    }
    private Literal getBindDIV(string ddlID, string strBindRowID,DataTable dtBind,bool isTextBox)
    {
        string divContent = "";
        try
        {
            bool includeEmpty = getExtendProperty(dtBind, "IncludeEmpty");
            string bindContent = isViewMode() == true ? "" : getBindContent(strBindRowID, "DIV_" + ddlID, ddlID, dtBind, isTextBox, includeEmpty);            
            if (bindContent.Length > 0)
            {
                divContent = getContent(HttpContext.Current.Server.MapPath("") + @"\scripts\lookup.txt");
                divContent = divContent.Replace("<<divid>>", "DIV_" + ddlID);
                divContent = divContent.Replace("<<includeEmpty>>", includeEmpty == true ? "true" : "false");
                divContent = divContent.Replace("<<content>>", bindContent);
                divContent = divContent.Replace("<<controlid>>", ddlID);
            }
        }
        catch (Exception e)
        {
            divContent = "";
            LogWriter.WriteLog("Error in getBindDIV: " + e.Message);
        }
        Literal ll = new Literal();
        //ll.ID = "ll_DIV_" + ddlID;
        ll.Text = divContent;
        return ll;

    }
    private bool getExtendProperty(DataTable dt,string propertyName)
    {
        try
        {
            if (dt == null) return false;
            if (dt.ExtendedProperties.ContainsKey(propertyName))
                return (bool)dt.ExtendedProperties[propertyName];
            return false;
        }
        catch (Exception e)
        {
            return false;
        }
    }
    private bool isViewMode()
    {
        if (HttpContext.Current.Request.QueryString["VMODE"] != null)
            if (HttpContext.Current.Request.QueryString["VMODE"] == "1")
                return true;
        return false;
    }
    private string getBindContent(string strBindRowID,string DIVID,string controlId,DataTable dtBind,bool isTextBox,bool includeEmptyValues)
    {
        //LogWriter.WriteLog(DateTime.Now.ToString());
        if (!isTextBox)
        {
            if (dtBind == null) return "";
            if (dtBind.Rows.Count < 1) return "";
        }
        try
        {
            //return strBindRowID;
            string constant = "ctl00_ContentPlaceHolder3_";
            System.Text.StringBuilder retContent = new System.Text.StringBuilder();            
            //string retContent = "";             
            DataSet ds = new DataSet(); int recCount = 0;
            HDDatabase hdd = new HDDatabase(); string bindText = ""; string bindValue = ""; string bindTable = ""; string bindParam = "";
            string additionalFields = ""; string[] addFieldsArray;
            ds = hdd.GetDataset("select * from sy_bnd where af_row_id = '" + strBindRowID + "';");
            if (ds != null)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    bindTable = ds.Tables[0].Rows[0]["bind_table"].ToString();
                    bindValue = ds.Tables[0].Rows[0]["bind_value"].ToString();
                    bindText = ds.Tables[0].Rows[0]["bind_text"].ToString();
                    bindParam = ds.Tables[0].Rows[0]["bind_parameter"].ToString().Trim();
                    additionalFields = ds.Tables[0].Rows[0]["additional_fields"].ToString().Trim();
                    includeEmptyValues = ds.Tables[0].Rows[0]["include_empty_value"] == System.DBNull.Value ? false : Convert.ToBoolean(ds.Tables[0].Rows[0]["include_empty_value"]);
                    if (bindTable.IndexOf(",") < 0) bindTable = "[" + bindTable + "]";
                }
                if (additionalFields.Length < 1 && !isTextBox)
                {
                    ds = null;
                    hdd = null;
                    return "";
                }
                addFieldsArray = additionalFields.Split(',');
                if (additionalFields.Trim().Length > 0) additionalFields = "," + additionalFields;
                if (bindTable.Length > 0)
                {
                    ////ds = hdd.GetDataset("select " + bindValue + "," + bindText + " from " + bindTable + (bindParam.Length > 0 ? " where " + bindParam : ""));
                    ////ds = hdd.GetDataset("select * from " + bindTable + (bindParam.Length > 0 ? " where " + bindParam : ""));
                    if (isTextBox)
                    {
                        // Added by 'Imran Gani' on 19-Mar-2014, for bind where key handling
                        string BindSQL = "select " + bindValue + " as Val, " + bindText + " as Fld" + " from " + bindTable;
                        DataTable dt_TempPara = hdd.GetDataTable(BindSQL + (bindParam.Length > 0 ? " where " + bindParam : ""));
                        if (dt_TempPara == null || dt_TempPara.Columns.Count == 0)
                            dt_TempPara = hdd.GetDataTable(BindSQL + (bindParam.Length > 0 ? " " + bindParam : ""));
                        dtBind = dt_TempPara.Copy();
                        //dtBind = hdd.GetDataTable("select " + bindValue + " as Val, " + bindText + " as Fld" + " from " + bindTable + (bindParam.Length > 0 ? " where " + bindParam : ""));
                    }
                    if (dtBind.Rows.Count < 1)
                    {
                        ds = null;
                        hdd = null;
                        return "";
                    }
                    //ds = hdd.getdataset("select " + bindValue + " as bindValue, " + bindText + " as bindText" + additionalFields + " from " + bindTable + (bindParam.Length > 0 ? " where " + bindParam : ""));
                    ////ds = hdd.GetDataset("select " + bindValue + "," + bindText + "" + additionalFields + " from " + bindTable + (bindParam.Length > 0 ? " where " + bindParam : ""));
                    //if (ds != null)
                    {
                        //retContent.Append("<div align='right' valign='center'>");
                        retContent.Append("<table style='border-color:#B5B5B5' border='0' cellpadding='2' cellspacing='0'>");
                        retContent.Append("<tr><td style='border-bottom: solid 1px #A0A0A0;' align='right' colspan='3'>");
                        retContent.Append("<a href='#' onClick=\"javascript:document.getElementById('" + constant + controlId + "').focus();document.getElementById('" + DIVID + "').style.display='none';return false;\"><img border='0' src='Images/xClose.gif' title='Close this window'></img></a>");
                        retContent.Append("&nbsp;&nbsp;&nbsp;&nbsp;</td><tr>");
                        //retContent.Append("</td></tr></table>");
                        //retContent.Append("&nbsp;&nbsp;&nbsp;</div>");                        

                        retContent.Append("<tr><td colspan='3' class='defaultFont'><font size='2px'>");
                        retContent.Append("&nbsp;&nbsp;&nbsp;Select your choice below");
                        retContent.Append("</font></td><tr>");

                        retContent.Append("<tr><td width='2px'>&nbsp;");
                        retContent.Append("</td>");
                        retContent.Append("<td>");
                        retContent.Append("<table id='" + "tbl_div_" + controlId +"' style='border-color:#B5B5B5' border='0' cellpadding='2' cellspacing='0'>");

                        //add header
                        
                        retContent.Append("<tr>");

                        retContent.Append("<td style=\"white-space:nowrap;background-color:#000000;\" height='20px' valign='middle' border='0'>&nbsp;</td>");

                        retContent.Append("<td style=\"white-space:nowrap;background-color:#000000;\" height='20px' border='0' class='defaultFont'><b><font size='1px' color='#FFFFFF'>");
                        if (getExactColumnName(bindText).IndexOf("+") > -1)
                            retContent.Append("&nbsp;");
                        else
                            retContent.Append( bindText);
                        retContent.Append("</font></b></td>");

                        //for (int i = 0; i < addFieldsArray.Length; i++)
                        //for (int k = 2; k < ds.Tables[0].Columns.Count; k++)
                        for (int k = 2; k < dtBind.Columns.Count; k++)
                        {
                            retContent.Append("<td style=\"white-space:nowrap;background-color:#000000;\" height='20px' border='0' class='defaultFont'><b><font size='1px' color='#FFFFFF'>");
                            //retContent.Append(addFieldsArray[i];
                            retContent.Append(dtBind.Columns[k].ColumnName);
                            retContent.Append("</font></b></td>");
                        }
                        retContent.Append("</tr>");
                        
                        foreach (DataRow dr in dtBind.Rows)
                        {
                            retContent.Append("<tr onMouseOver=\"this.className='selectDIVBG'\" onMouseOut=\"this.className=" + (recCount % 2 == 0 ? "'selectDIV0'" : "'selectDIV1'") + "\"" + (recCount % 2 == 0 ? " class='selectDIV0' " : " class='selectDIV1'") + ">");

                            //retContent.Append("<td" + (recCount % 2 == 0 ? " class='selectDIV0' " : " class='selectDIV1' ") + " style=\"white-space:nowrap;\" height='20px' valign='middle' border='0'>";
                            retContent.Append("<td style=\"white-space:nowrap;\" height='20px' valign='middle' border='0'>");
                            if (!isTextBox)
                            {
                                //retContent.Append("&nbsp;<a href='#' id='" + "hyper_" + controlId + recCount.ToString() + "' onClick=\"javascript:document.getElementById('" + constant + controlId + "').selectedIndex=" + (includeEmptyValues == false ? recCount.ToString() : Convert.ToString(recCount + 1)) + ";document.getElementById('" + DIVID + "').style.display = 'none';return false;\"><img border='0' id='" + "img_" + controlId + recCount.ToString() + "' src='Images/tick4.gif' title='Click to select this'></img></a>");//onMouseOver=\"this.src='Images/check.gif'\" onMouseOut=\"this.src='Images/nocheck.gif'\"
                                retContent.Append("&nbsp;<a href='#' id='" + "hyper_" + controlId + recCount.ToString() + "' onClick=\"javascript:handleDropDownLookup('" + constant + "','" + controlId +"'," + (includeEmptyValues==true ? "true" : "false") + ",'" + recCount.ToString() + "','" + DIVID + "');\"><img border='0' id='" + "img_" + controlId + recCount.ToString() + "' src='Images/tick4.gif' title='Click to select this'></img></a>");//onMouseOver=\"this.src='Images/check.gif'\" onMouseOut=\"this.src='Images/nocheck.gif'\"
                            }
                            else
                                retContent.Append("&nbsp;<a href='#' id='" + "hyper_" + controlId + recCount.ToString() + "' onClick=\"javascript:document.getElementById('" + constant + controlId + "').value='" + dr["Val"].ToString() + "';document.getElementById('" + DIVID + "').style.display = 'none';return false;\"><img border='0' id='" + "img_" + controlId + recCount.ToString() + "' src='Images/tick4.gif' title='Click to select this'></img></a>");
                            retContent.Append("</td>");

                            //retContent.Append( "<td" + (recCount % 2 == 0 ? " class='selectDIV0' " : " class='selectDIV1' ") + " style=\"white-space:nowrap;\" height='20px' border='0'>";
                            retContent.Append("<td style=\"white-space:nowrap;\" height='20px' border='0'>");
                            //retContent.Append( dr["bindText"].ToString();
                            retContent.Append(HttpUtility.HtmlEncode(dr["Fld"].ToString())); // Encoded by 'Imran Gani' on 27-Dec-12
                            retContent.Append("</td>");

                            //for (int i = 0; i < addFieldsArray.Length; i++)
                            for(int k=2;k<dtBind.Columns.Count;k++)
                            {
                                //if (addFieldsArray[i].Trim().Length < 1) continue;
                                //retContent.Append( "<td onMouseOver=\"this.className='selectDIVBG'\" onMouseOut=\"this.className='" + (recCount % 2 == 0 ? " class='selectDIV0' " : " class='selectDIV1' ") + "'\"" + (recCount % 2 == 0 ? " class='selectDIV0' " : " class='selectDIV1' ") + " style=\"white-space:nowrap;\" height='20px' border='0'>";
                                retContent.Append("<td style=\"white-space:nowrap;\" height='20px' border='0'>");
                                //retContent.Append( dr.Table.Columns.Contains(addFieldsArray[i]) ? dr[addFieldsArray[i]].ToString() : dr[getExactColumnName(addFieldsArray[i])].ToString();
                                retContent.Append(HttpUtility.HtmlEncode(getValueUpto(dr[dtBind.Columns[k]].ToString(), 35))); // Encoded by 'Imran Gani' on 27-Dec-12
                                retContent.Append("</td>");
                            }

                            retContent.Append("</tr>");
                            recCount++;
                        }
                        retContent.Append("</table>");
                        retContent.Append("</td>");
                        retContent.Append("<td width='2px'>&nbsp;");
                        retContent.Append("</td></tr>");

                        retContent.Append("<tr><td align='right' colspan='3'>");
                        //retContent.Append("<br><div align='right' valign='center'>");
                        retContent.Append("<a href='#' onClick=\"javascript:document.getElementById('" + constant + controlId + "').focus();document.getElementById('" + DIVID + "').style.display='none';return false;\"><img border='0' src='Images/xClose.gif' title='Close this window'></img></a>");
                        retContent.Append("&nbsp;&nbsp;&nbsp;</td><tr></table>");
                        //retContent.Append("</td></tr></table>");
                        //retContent.Append("&nbsp;&nbsp;&nbsp;</div>");
                        //retContent.Append("<br /><a href='#' onClick=\"javascript:document.getElementById('" + DIVID + "').style.display = 'none';document.getElementById('" + constant + controlId + "').focus();return false;\"><img border='0' src='Images/close_15.gif' title='Close this window'></img></a>");
                        //retContent.Append("<table width='100%'><tr><td align='right'><a href='#' onClick=\"javascript:document.getElementById('" + constant + controlId + "').focus();document.getElementById('" + DIVID + "').style.display='none';return false;\"><img border='0' src='Images/close_15.gif' title='Close this window'></img></a></td></tr></table>";
                    }
                }
            }
            hdd = null;
            //LogWriter.WriteLog(DateTime.Now.ToString());
            return retContent.ToString();
        }
        catch (Exception e)
        {
            return "";
        }        
    }
    private string getValueUpto(string inp, int length)
    {
        if (length == 0) return inp;
        if (inp.Trim() == "") return inp;
        if (inp.Length < length) return inp;
        return inp.Substring(0, length - 1);
    }
    private string getExactColumnName(string inpColName)
    {
        if (inpColName.IndexOf(".") < 0) return inpColName;
        return inpColName.Substring(inpColName.IndexOf(".") + 1);
    }
    public void addMandatoryValidator(ref HtmlTableCell cc, Control ctrl)//created by sanal on 14 Dec 2007
    {
        try
        {
            Literal lReq = new Literal();
            lReq.ID = "reqimg_" + ctrl.ID; // Added by srivatsan
            //lReq.Text = "<span style='color: red; font-size: 11pt;'>*</span>";
            lReq.Text = @"&nbsp;<img src=""Images/star.gif"" alt=""Required Field""></img>";
            cc.Controls.Add(lReq);
            RequiredFieldValidator rfv = new RequiredFieldValidator();
            rfv.ID = "rfv_" + ctrl.ID;
            //rfv.Display = ValidatorDisplay.Dynamic;        
            //rfv.ErrorMessage = "<IMG src='Images/warning_small.gif' title='This is a mandatory field'></img>";
            rfv.ErrorMessage = "This is a required field.";
            rfv.Display = ValidatorDisplay.None;
            rfv.ControlToValidate = ctrl.ID;
            cc.Controls.Add(rfv);
            ValidatorCalloutExtender vce = new ValidatorCalloutExtender();
            vce.TargetControlID = rfv.ID;
            vce.WarningIconImageUrl = "Images/warning_small.gif";
            vce.ID = "vce_" + ctrl.ID;
            vce.HighlightCssClass = "maskInvalid";
            cc.Controls.Add(vce);
            //cc.VAlign = "bottom";
        }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error in addMandatoryValidator: " + e.Message);
        }
    }
    private void loadDateTimeScript(DataRow dr, ref HtmlTableCell htc, string id, ref string script)//created by sanal on 12 Dec 2007
    {        
        string constant = "ctl00_ContentPlaceHolder3_";
        switch (dr["control_attrib_type"].ToString().ToUpper())
        {
            case "DA":
                //htc.Controls.Add(getDateLiteral(id,constant));
                //addtoForm(htc, getDateLabel(id, constant));
                script = script + getContent(HttpContext.Current.Server.MapPath("") + @"\JSCalendar\datescript.txt").Replace("<<controlid>>", constant + id).Replace("<<functionname>>", id);
                break;
            case "DT":
                //htc.Controls.Add(getDateTimeLiteral(id,constant));
                //addtoForm(htc, getDateLabel(id, constant));
                script = script + getContent(HttpContext.Current.Server.MapPath("") + @"\JSCalendar\datetimescript.txt").Replace("<<controlid>>", constant + id).Replace("<<functionname>>", id);
                break;
        }
    }
    private void addDateIfDateTime(DataRow dr, ref HtmlTableCell htc, string id)//created by sanal on 12 Dec 2007
    {
        try
        {
            string constant = "ctl00_ContentPlaceHolder3_";
            switch (dr["control_attrib_type"].ToString().ToUpper())
            {
                case "DA":
                    //htc.Controls.Add(getDateLiteral(id,constant));
                    htc.Controls.Add(addAjaxCalendarDate(id));
                    ////addtoForm(htc, getDateLabel(id, constant));
                    break;
                case "DT":
                    //htc.Controls.Add(getDateTimeLiteral(id, constant));
                    //htc.Controls.Add(addAjaxCalendarDateTime(id));
                    addAjaxCalendarDateTime(id, ref htc);
                    //addtoForm(htc, getDateLabel(id, constant));
                    break;
            }
        }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error in addDateIfDateTime: " + e.Message);
        }
    }
    public CalendarExtender addAjaxCalendarDate(string id)
    {
        if (id.Length < 1) return null;
        CalendarExtender ce = new CalendarExtender();
        ce.ID = "ce_ajax_" + id;
        ce.Format = getUserDateFormat();// "dd-MMM-yyyy";
        ce.TargetControlID = id;
        return ce;
    }
    private string getUserDateFormat()
    {
        #region Old code commented by 'Imran Gani' on 28-Feb-2014, for MBLocale
        //Localization ll = new Localization();
        //string ret = ll.getDateFormat();
        //ll = null;
        #endregion
        string ret = MBLocale.MBLocalization.getDateFormat(HttpContext.Current.Session["userlocale"].ToString());
        return ret;
    }
    public void addAjaxCalendarDateTime(string id,ref HtmlTableCell htc)
    {
        if (id.Length < 1) return;
        CalendarExtender ce = new CalendarExtender();
        ce.ID = "ce_ajax_" + id;
        ce.Format = getUserDateFormat() + " hh:mm tt";// "dd-MMM-yyyy hh:ss tt";
        ce.TargetControlID = id;
        //return ce;
        htc.Controls.Add(ce);
        //MaskedEditExtender me = new MaskedEditExtender();
        //me.ID = "me_ajax_" + id;
        //me.TargetControlID = id;
        //htc.Controls.Add(me);
        //MaskedEditValidator mev = new MaskedEditValidator();
        //mev.ID = "mev_ajax_" + id;
        //mev.ControlExtender = "me_ajax_" + id;
        //mev.ControlToValidate = id;
        //mev.ErrorMessage = "Not a valid DateTime.";
        //mev.IsValidEmpty = true;
        //mev.ForeColor = System.Drawing.Color.Red;
        //htc.Controls.Add(mev);
    }
    private void addtoForm(Control c, Label s)
    {
        //HtmlForm hf = HttpContext.Current.Response.
        //hf.Controls.Add(s);
        //if (c is HtmlForm)
        //    c.Controls.Add(s);
        //else
        //{
        //    if (c.Parent!=null)
        //        addtoForm(c.Parent, s);
        //}
    }
    
    private Literal getDateLiteral(string id, string constant)//created by sanal on 12 Dec 2007
    {
        Literal lb = new Literal();
        //lb.ID = "afdatelbl" + id;
        lb.Text = getContent(HttpContext.Current.Server.MapPath("") + @"\JSCalendar\datescript.txt").Replace("<<controlid>>", constant + id).Replace("<<functionname>>", id);
        //lb.Text = getContent(System.Reflection.Assembly.GetExecutingAssembly().Location + @"\JSCalendar\datescript.txt").Replace("<<controlid>>", id).Replace("<<functionname>>", id);
        return lb;
    }
    private Literal getDateTimeLiteral(string id, string constant)//created by sanal on 12 Dec 2007
    {
        Literal lb = new Literal();
        //lb.ID = "afdatelbl" + id;
        lb.Text = getContent(HttpContext.Current.Server.MapPath("") + @"\JSCalendar\datetimescript.txt").Replace("<<controlid>>", constant + id).Replace("<<functionname>>", id);
        //lb.Text = getContent(System.Reflection.Assembly.GetExecutingAssembly().Location + @"\JSCalendar\datetimescript.txt").Replace("<<controlid>>", id).Replace("<<functionname>>", id);
        return lb;
    }
    private Label getDateLabel(string id,string constant)//created by sanal on 12 Dec 2007
    {
        Label lb = new Label();
        lb.ID = "afdatelbl" + id;
        lb.Text = getContent(HttpContext.Current.Server.MapPath("") + @"\JSCalendar\datescript.txt").Replace("<<controlid>>",constant + id).Replace("<<functionname>>", id);
        //lb.Text = getContent(System.Reflection.Assembly.GetExecutingAssembly().Location + @"\JSCalendar\datescript.txt").Replace("<<controlid>>", id).Replace("<<functionname>>", id);
        return lb;
    }
    private Label getDateTimeLabel(string id, string constant)//created by sanal on 12 Dec 2007
    {
        Label lb = new Label();
        lb.ID = "afdatelbl" + id;
        lb.Text = getContent(HttpContext.Current.Server.MapPath("") + @"\JSCalendar\datetimescript.txt").Replace("<<controlid>>",constant+ id).Replace("<<functionname>>", id);
        //lb.Text = getContent(System.Reflection.Assembly.GetExecutingAssembly().Location + @"\JSCalendar\datetimescript.txt").Replace("<<controlid>>", id).Replace("<<functionname>>", id);
        return lb;
    }
    private string getContent(string fileName)//created by sanal on 12 Dec 2007
    {
        try
        {
            if (!File.Exists(fileName)) return "";
            string temp = "";
            StreamReader sr = new StreamReader(fileName);
            temp = sr.ReadToEnd();
            sr.Close(); sr = null;
            return temp;
        }
        catch (Exception e)
        {
            return "";
        }
    }
    public string getAutoNumberValue(string ObjId, string Field, int PageRowCount)
    {
        HDDatabase HDD = new HDDatabase();
        string sObjectName = HDD.GetColumnValue("Select object_table from sy_obj where object_id = '" + ObjId.Replace("'", "''") + "'");
        string sVal = HDD.GetColumnValue("select max([" + Field.Replace("'", "''") + "]) + 1 as AN from [" + sObjectName.Replace("'", "''") + "]");
        HDD = null;
        sVal = sVal == "" ? "1" : sVal;
        if (PageRowCount > 1)
            sVal = Convert.ToString(Convert.ToInt32(sVal) + PageRowCount - 1);
        return sVal;
    }

    public ArrayList GetCmdObj(string strFileName, bool IsSystemGenerated)
    {
        ArrayList arlReturn = new ArrayList();
        StreamReader SR = new StreamReader(strFileName);
        string strLine = "";
        string strSql = "";
        bool blnSqlEnd = false;
        while ((strLine = SR.ReadLine()) != null)
        {
            strLine = strLine.Trim();
            if (!strLine.StartsWith("--"))
            {
                if (strLine.ToUpper() != "GO")
                {
                    strSql += strLine + " ";
                }

                if (IsSystemGenerated)
                {
                    if (strLine.ToUpper() == "GO")
                    {
                        blnSqlEnd = true;
                    }
                }
                else
                {
                    blnSqlEnd = true;
                }

                if (blnSqlEnd)
                {
                    if (strSql.Trim() != "")
                    {
                        SqlCommand cmdObj = new SqlCommand();
                        cmdObj.CommandText = strSql;
                        arlReturn.Add(cmdObj);
                    }
                    strSql = "";
                    blnSqlEnd = false;
                }
            }
        }
        SR.Close(); SR = null;
        return arlReturn;
    }

    public SqlCommand GetHelpCmdObj(string strFileName, bool IsSystemGenerated)
    {
        StreamReader SR = new StreamReader(strFileName);
        string strSql = "";
        bool blnSqlEnd = false;
        strSql = SR.ReadToEnd();//.Replace(Environment.NewLine, "").Replace(";insert", ";" + Environment.NewLine + "insert");
        SR.Close(); SR = null;

        SqlCommand cmdObj = new SqlCommand();
        cmdObj.CommandText = strSql;
        return cmdObj;
    }

    public void SetDefaultValueForOwnerID(ref DropDownList DDL, string strActualCtrlId) //In add or copy mode of page default value will be set to logged in user
    {
        if (strActualCtrlId.ToLower() == ownerid)
        {
            AddafadminInDropDown(ref DDL);
        }

        if (HttpContext.Current.Request.QueryString["PK"] == null)
        {
            if (strActualCtrlId.ToLower() == ownerid)
            {
                DDL.SelectedValue = HttpContext.Current.Session["user_afrowid"].ToString();
            }

        }

        if (HttpContext.Current.Request.QueryString["CPY"] != null)
        {
            if (strActualCtrlId.ToLower() == ownerid)
            {
                DDL.SelectedValue = HttpContext.Current.Session["user_afrowid"].ToString();
            }
        }


    }
    public void SetDefaultValueForOwnerID(ref TextBox Text,ref HiddenField hf, string strActualCtrlId) //In add or copy mode of page default value will be set to logged in user
    {
        if (strActualCtrlId.ToLower() == ownerid)
        {
            //AddafadminInDropDown(ref );
        }
        if (HttpContext.Current.Request.QueryString["PK"] == null)
        {
            if (strActualCtrlId.ToLower() == ownerid)
            {
                //DDL.SelectedValue = HttpContext.Current.Session["user_afrowid"].ToString();
                Text.Text = HttpContext.Current.Session["userid"].ToString();
                hf.Value = HttpContext.Current.Session["user_afrowid"].ToString();
            }

        }

        if (HttpContext.Current.Request.QueryString["CPY"] != null)
        {
            if (strActualCtrlId.ToLower() == ownerid)
            {
                //DDL.SelectedValue = HttpContext.Current.Session["user_afrowid"].ToString();
                Text.Text = HttpContext.Current.Session["userid"].ToString();
                hf.Value = HttpContext.Current.Session["user_afrowid"].ToString();
            }
        }


    }


    private void AddafadminInDropDown(ref DropDownList DDL)
    {
        HDDatabase HDD = new HDDatabase();
        try
        {
            if (HttpContext.Current.Session["user_afrowid"] != null)
            {
                if (HttpContext.Current.Session["user_afrowid"].ToString() == "e51e0327224a2eb9")
                {
                    
                    ListItem item = new ListItem(HDD.GetColumnValue("select user_id from sy_usr where af_row_id = 'e51e0327224a2eb9'"), "e51e0327224a2eb9");
                    if (!DDL.Items.Contains(item))
                    {
                        DDL.Items.Add(item);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : AddafadminInDropDown:" + ex.Message);
        }
        finally
        {
            HDD = null;
        }
    }


    //Added by srivatsan on July 15 2009 For Text Box Search
    //Adds Search Image for Bind controls
    public void AddSearchLink(ref HtmlTableCell htc, string strActualCtrlId, string hiddenfieldid,string textboxid, string strBindRowID)
    {
        Label lbl = new Label();
        try
        {
            if(HttpContext.Current.Request.QueryString["Vmode"]==null || CheckForDashboards())
            {
            HDDatabase HDD = new HDDatabase();
            string pagename = HDD.GetColumnValue("select top 1 B.page_name from sy_bnd A, sy_pg B where A.bind_table = B.page_table_name and A.af_row_id = '" + strBindRowID + "'");
            HDD = null;

            string strPK = "";
            if (HttpContext.Current.Request.QueryString["PK"] != null)
            {
               strPK  = HttpContext.Current.Request.QueryString["PK"].ToString();
            }
            string strpgs_id = "";
            if (HttpContext.Current.Request.QueryString["pgs_id"] != null)
            {
                strpgs_id = HttpContext.Current.Request.QueryString["pgs_id"].ToString();
            }
            lbl.Text = "<img class=\"SearchPopup\" src=Images/search.GIF></img></a>";
            lbl.Attributes.Add("onclick", "javascript:openlookupwindow('"+hiddenfieldid+"','"+textboxid+"','"+strBindRowID+"','"+strPK+"','"+strpgs_id+"');");
            lbl.CssClass = "SearchPopup";
            lbl.ID = hiddenfieldid+"_img_search_popup";
            if (pagename != "")
            {
                lbl.ToolTip = "Click here for " + pagename + " Lookup";
            }
            else
            {
                lbl.ToolTip = "Click here for Lookup window";
            }
            htc.VAlign = "middle";
            htc.Controls.Add(lbl);
        }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : AddSearchLink :"+ex.Message);
        }
        finally
        {
            lbl = null;
        }

    }

    public void AddSearchLinkForMasterDetail(ref HtmlTableCell htc, string strActualCtrlId, string hiddenfieldid, string textboxid, string strBindRowID,string fld,string tablename)
    {
        Label lbl = new Label();
        try
        {
            HDDatabase HDD = new HDDatabase();
            string pagename = HDD.GetColumnValue("select top 1 B.page_name from sy_bnd A, sy_pg B where A.bind_table = B.page_table_name and A.af_row_id = '" + strBindRowID + "'");
            HDD = null;

            string strPK = "";
            if (HttpContext.Current.Request.QueryString["PK"] != null)
            {
                strPK = HttpContext.Current.Request.QueryString["PK"].ToString();
            }
            string strpgs_id = "";
            if (HttpContext.Current.Request.QueryString["pgs_id"] != null)
            {
                strpgs_id = HttpContext.Current.Request.QueryString["pgs_id"].ToString();
            }
            lbl.Text = "<img class=\"SearchPopup\" src=Images/search.GIF></img></a>";
            //lbl.Attributes.Add("onclick", "javascript:openlookupwindow('" + hiddenfieldid + "','" + textboxid + "','" + strBindRowID + "','" + strPK + "','" + strpgs_id + "','"+fld+"','"+tablename+"');");

            lbl.Attributes.Add("onclick", "javascript:openlookupwindowForMasterDetail('" + hiddenfieldid + "','" + textboxid + "','" + strBindRowID + "','" + strPK + "','" + strpgs_id + "','" + fld + "','" + tablename + "');");
            lbl.CssClass = "SearchPopup";
            lbl.ID = hiddenfieldid + "_img_search_popup";
            if (pagename != "")
            {
                lbl.ToolTip = "Click here for " + pagename + " Lookup";
            }
            else
            {
                lbl.ToolTip = "Click here for Lookup window";
            }
            htc.VAlign = "middle";
            htc.Controls.Add(lbl);
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : AddSearchLink :" + ex.Message);
        }
        finally
        {
            lbl = null;
        }

    }

    public void ConfigureDDE(ref DropDownList DDL, DataRow drpgctr, string strBindRowID, ref HtmlTableCell htc, HtmlForm frmobj, string[] BindFields)
    {
        BindControl BC = new BindControl();
        DataTable dtbind = new DataTable();
        GenerateGrid GG = new GenerateGrid();
        HDDatabase HDD = new HDDatabase();
        HiddenField hf = new HiddenField();
        string valuefield = "";
        string displayfield = "";
        string strPagesetRowId = "";
        string strMenuRowId = "";
        string page_id = "";
        string strDisplayValue = "";
        try
        {

            if (drpgctr != null)
                if (strBindRowID != "")
                {
                    DDL.Items.Clear();
                    BC.Bind(strBindRowID, DDL, ref dtbind, drpgctr);
                    if (BindFields != null)
                        if (BindFields.Length > 0)
                        {
                            strPagesetRowId = BindFields[2].ToString();
                            page_id = BindFields[4].ToString();
                            strMenuRowId = BindFields[3].ToString();
                            valuefield = BindFields[0].ToString();
                            displayfield = BindFields[1].ToString();

                        }
                    DDL.Attributes.Add("OnChange", "javascript:ExtendedDropDownAction('" + DDL.ID + "','" + strBindRowID + "','" + strPagesetRowId + "','" + strMenuRowId + "','','" + valuefield + "','" + displayfield + "');");
                    hf.ID = "hf_DDE_" + DDL.ID;
                    ////hf.Value = GG.getEditPage(HDD, strPagesetRowId) + "?pgs_id=" + strPagesetRowId + "&mn=" + HttpContext.Current.Request.QueryString["mn"].ToString() + "";
                    hf.Value = GG.getEditPage(HDD, strMenuRowId) + "|" + strPagesetRowId + "|" + strMenuRowId;
                    htc.Controls.Add(hf);

                    HiddenField hf_af_row_id = new HiddenField();
                    hf_af_row_id.ID = "hf_RowID_" + DDL.ID;
                    htc.Controls.Add(hf_af_row_id);

                    HiddenField hfDisplayvalue = new HiddenField();
                    hfDisplayvalue.ID = "hf_DDE_DV_" + DDL.ID;
                    htc.Controls.Add(hfDisplayvalue);

                    if (frmobj != null)
                        if (frmobj.Page.IsPostBack)
                            if (frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$" + DDL.ID] != null)
                            {
                                    BC = new BindControl();
                                    DynamicDisplayI DDI = new DynamicDisplayI();
                                    DropDownList ddl = (DropDownList)DDI.FindControl(frmobj.Controls, DDL.ID);
                                    DataTable dtbinddata = HDD.GetDataTable(BC.GetBindSql(strBindRowID));
                                    if (dtbinddata != null)
                                    {

                                        if (frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$" + DDL.ID].ToString().Trim() != "")
                                        {
                                            if (!CheckIfDefaultFields(ref DDL, frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$" + DDL.ID].ToString().Trim()))
                                            {
                                                DataRow[] drrdata = null;
                                                try
                                                {
                                                    drrdata = dtbinddata.Select("val='" + frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$" + DDL.ID].ToString().Replace("'", "''") + "'");
                                                }
                                                catch { }
                                                if (drrdata != null)
                                                {
                                                    if (drrdata.Length > 0)
                                                    {
                                                        if (DDL.Items.Contains(new ListItem(drrdata[0]["fld"].ToString(), drrdata[0]["val"].ToString())))
                                                        {
                                                            //DDL.Items.FindByValue(drrdata[0]["val"].ToString()).Selected = true;
                                                            ListItem item = DDL.Items.FindByValue(drrdata[0]["val"].ToString());
                                                            DDL.Items.Remove(item);
                                                            DDL.Items.Insert(0, item);
                                                            DDL.SelectedIndex = 0;
                                                        }
                                                        else
                                                        {
                                                            DDL.Items.Insert(0, new ListItem(drrdata[0]["fld"].ToString(), drrdata[0]["val"].ToString()));
                                                            DDL.SelectedIndex = 0;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (DDL.Items.FindByText(frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$" + DDL.ID].ToString()) != null)
                                                        {
                                                            //DDL.Items.FindByText(frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$" + DDL.ID].ToString()).Selected = true;
                                                            ListItem item = DDL.Items.FindByText(frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$" + DDL.ID].ToString());
                                                            DDL.Items.Remove(item);
                                                            DDL.Items.Insert(0, item);
                                                            DDL.SelectedIndex = 0;
                                                        }
                                                        else
                                                        {
                                                            DDL.Items.Insert(0, frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$" + DDL.ID].ToString());
                                                            DDL.SelectedIndex = 0;
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    DDL.Items.Insert(0, frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$" + DDL.ID].ToString());
                                                    DDL.SelectedIndex = 0;
                                                }

                                                strDisplayValue = frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$" + DDL.ID];
                                            }
                                        }
                                        else
                                        {
                                            if (frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$hf_DDE_DV_" + DDL.ID] != null)
                                            {
                                                if (!CheckIfDefaultFields(ref DDL, frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$hf_DDE_DV_" + DDL.ID].ToString()))
                                                {
                                                    DataRow[] drrdata = null;
                                                    try
                                                    {
                                                        drrdata = dtbinddata.Select("fld='" + frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$hf_DDE_DV_" + DDL.ID].ToString().Replace("'", "''") + "'");
                                                    }
                                                    catch { }
                                                    if (drrdata != null)
                                                    {
                                                        if (drrdata.Length > 0)
                                                        {
                                                            if (DDL.Items.Contains(new ListItem(drrdata[0]["fld"].ToString(), drrdata[0]["val"].ToString())))
                                                            {
                                                                ListItem item = new ListItem(drrdata[0]["fld"].ToString(), drrdata[0]["val"].ToString());

                                                                //int index = DDL.Items.IndexOf(item);
                                                                //DDL.SelectedIndex = index;
                                                                //DDL.Items.FindByValue(drrdata[0]["val"].ToString()).Selected = true;

                                                                DDL.Items.Remove(item);
                                                                DDL.Items.Insert(0, item);
                                                                DDL.SelectedIndex = 0;
                                                            }
                                                            else
                                                            {
                                                                DDL.Items.Insert(0, new ListItem(drrdata[0]["fld"].ToString(), drrdata[0]["val"].ToString()));
                                                                DDL.SelectedIndex = 0;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (DDL.Items.FindByText(frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$hf_DDE_DV_" + DDL.ID].ToString()) != null)
                                                            {
                                                                ListItem item = new ListItem(frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$hf_DDE_DV_" + DDL.ID].ToString());
                                                                //int index = DDL.Items.IndexOf(item);
                                                                //DDL.SelectedIndex = index;
                                                                //DDL.Items.FindByText(frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$hf_DDE_DV_" + DDL.ID].ToString()).Selected = true;
                                                                DDL.Items.Remove(item);
                                                                DDL.Items.Insert(0, item);
                                                                DDL.SelectedIndex = 0;
                                                            }
                                                            else
                                                            {
                                                                DDL.Items.Insert(0, new ListItem(frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$hf_DDE_DV_" + DDL.ID].ToString()));
                                                                DDL.SelectedIndex = 0;
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        DDL.Items.Insert(0, new ListItem(frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$hf_DDE_DV_" + DDL.ID].ToString()));
                                                        DDL.SelectedIndex = 0;
                                                    }

                                                    strDisplayValue = frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$hf_DDE_DV_" + DDL.ID];
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (!CheckIfDefaultFields(ref DDL, frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$" + DDL.ID].ToString().Trim()))
                                            DDL.Items.Insert(0, frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$" + DDL.ID].ToString());
                                        DDL.SelectedIndex = 0;
                                    }

                                    //RemoveEmptyValue(ref DDL);

                                    SetSelectedIndexonPostBack(ref DDL, strDisplayValue);
                                
                            }



                }

        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : ConfigureDDE : " + ex.Message);
        }
        finally
        {
            BC = null;
            GG = null;
            HDD = null;
        }
    }


    private DropDownList SetSelectedIndexonPostBack(ref DropDownList DDL,string displayvalue)
    {
        try
        {
            if(DDL.Items.Count>0)
                if (DDL.Items.Contains(new ListItem(displayvalue)))
                {
                    int index = DDL.Items.IndexOf(DDL.Items.FindByText(displayvalue));
                    if (index > -1)
                    {
                        DDL.SelectedIndex = 5;
                    }
                }
        }
        catch
        {
        }
        return DDL;
    }

    private void RemoveEmptyValue(ref DropDownList DDL)
    {
        try
        {
            if (DDL.Items.Contains(new ListItem("", "")))
            {
                DDL.Items.Remove(new ListItem("", ""));

                DDL.Items.Insert(0, "");
            }
        }
        catch
        {
        }
    }
    #region old ConfigureDDE
    //public void ConfigureDDE(ref DropDownList DDL, DataRow drpgctr, string strBindRowID, ref HtmlTableCell htc, HtmlForm frmobj, string[] BindFields)
    //{
    //    BindControl BC = new BindControl();
    //    DataTable dtbind = new DataTable();
    //    GenerateGrid GG = new GenerateGrid();
    //    HDDatabase HDD = new HDDatabase();
    //    HiddenField hf = new HiddenField();
    //    string valuefield = "";
    //    string displayfield = "";
    //    string pageset_id = "";
    //    string menu_id = "";
    //    string page_id = "";
    //    try
    //    {

    //        if (drpgctr != null)
    //            if (strBindRowID != "")
    //            {
    //                DDL.Items.Clear();
    //                BC.Bind(strBindRowID, DDL, ref dtbind, drpgctr);
    //                if (BindFields != null)
    //                    if (BindFields.Length > 0)
    //                    {
    //                        strPagesetRowId = BindFields[2].ToString();
    //                        page_id = BindFields[4].ToString();
    //                        menu_id = BindFields[3].ToString();
    //                        valuefield = page_id + "_" + BindFields[0].ToString();
    //                        displayfield = page_id + "_" + BindFields[1].ToString();

    //                    }
    //                //DDL.Attributes.Add("onmousedown", "javascript:ExtendedDropDownAction('" + DDL.ID + "','" + strBindRowID + "','','" + valuefield + "','" + displayfield + "');");
    //                DDL.Attributes.Add("OnChange", "javascript:ExtendedDropDownAction('" + DDL.ID + "','" + strBindRowID + "','','" + valuefield + "','" + displayfield + "');");
    //                hf.ID = "hf_DDE_" + DDL.ID;
    //                //hf.Value = GG.getEditPage(HDD, strPagesetRowId) + "?pgs_id=" + strPagesetRowId + "&mn=" + HttpContext.Current.Request.QueryString["mn"].ToString() + "";
    //                hf.Value = GG.getEditPage(HDD, menu_id) + "|" + strPagesetRowId + "|" + menu_id;
    //                htc.Controls.Add(hf);

    //                HiddenField hf_af_row_id = new HiddenField();
    //                hf_af_row_id.ID = "hf_RowID_" + DDL.ID;
    //                htc.Controls.Add(hf_af_row_id);

    //                HiddenField hfDisplayvalue = new HiddenField();
    //                hfDisplayvalue.ID = "hf_DDE_DV_" + DDL.ID;
    //                htc.Controls.Add(hfDisplayvalue);

    //                if (frmobj != null)
    //                {
    //                    if (frmobj.Page.IsPostBack)
    //                    {
    //                        if (frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$" + DDL.ID] != null)
    //                        {
    //                            //if (HttpContext.Current.Request.QueryString["PK"] == null)
    //                            //{
    //                            BC = new BindControl();
    //                            DynamicDisplayI DDI = new DynamicDisplayI();
    //                            DropDownList ddl = (DropDownList)DDI.FindControl(frmobj.Controls, DDL.ID);
    //                            DataTable dtbinddata = HDD.GetDataTable(BC.GetBindSql(strBindRowID));
    //                            if (dtbinddata != null)
    //                            {

    //                                if (frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$" + DDL.ID].ToString().Trim() != "")
    //                                {
    //                                    if (!CheckIfDefaultFields(ref DDL, frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$" + DDL.ID].ToString().Trim()))
    //                                    {
    //                                        DataRow[] drrdata = dtbinddata.Select("val='" + frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$" + DDL.ID].ToString() + "'");
    //                                        if (drrdata.Length > 0)
    //                                            DDL.Items.Insert(0, new ListItem(drrdata[0]["fld"].ToString(), drrdata[0]["val"].ToString()));
    //                                        else
    //                                            DDL.Items.Insert(0, frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$" + DDL.ID].ToString());
    //                                    }
    //                                }
    //                                else
    //                                {
    //                                    if (frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$hf_DDE_DV_" + DDL.ID] != null)
    //                                    {
    //                                        if (!CheckIfDefaultFields(ref DDL, frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$hf_DDE_DV_" + DDL.ID].ToString()))
    //                                        {
    //                                            DataRow[] drrdata = dtbinddata.Select("fld='" + frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$hf_DDE_DV_" + DDL.ID].ToString() + "'");
    //                                            if (drrdata.Length > 0)
    //                                                DDL.Items.Insert(0, new ListItem(drrdata[0]["fld"].ToString(), drrdata[0]["val"].ToString()));
    //                                            else
    //                                                DDL.Items.Insert(0, frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$hf_DDE_DV_" + DDL.ID].ToString());
    //                                        }
    //                                    }
    //                                }
    //                            }
    //                            else
    //                            {
    //                                if (!CheckIfDefaultFields(ref DDL, frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$" + DDL.ID].ToString().Trim()))
    //                                    DDL.Items.Insert(0, frmobj.Page.Request.Form["ctl00$ContentPlaceHolder3$" + DDL.ID].ToString());
    //                            }
    //                            //}
    //                        }

    //                    }
    //                }
    //            }

    //    }
    //    catch (Exception ex)
    //    {
    //        LogWriter.WriteLog("Error : ConfigureDDE : " + ex.Message);
    //    }
    //    finally
    //    {
    //        BC = null;
    //        GG = null;
    //        HDD = null;
    //    }
    //}
    #endregion

    private bool CheckIfDefaultFields(ref DropDownList DDL,string value)
    {
        bool status = false;
        ListItem list = null;
        try
        {
            if (value == "ADD")
            {
                list = new ListItem("--Add--", value);
                if (DDL.Items.Contains(list))
                {
                    DDL.Items[DDL.Items.IndexOf(list)].Selected = true;
                    status = true;
                }
            }
            else if (value == "SRH")
            {
                list = new ListItem("--Search--", value);
                if (DDL.Items.Contains(list))
                {
                    DDL.Items[DDL.Items.IndexOf(list)].Selected = true;
                    status = true;
                }
            }
            else if (value == "TYP")
            {
                list = new ListItem("--Type--", value);
                if (DDL.Items.Contains(list))
                {
                    DDL.Items[DDL.Items.IndexOf(list)].Selected = true;
                    status = true;
                }
            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : CheckIfDefaultFields :" + ex.Message);
        }
        finally
        {
            list = null;
        }
        return status;
    }

    public void AddDDEEditButton(ref HtmlTableCell htc, ref DropDownList DDL, string control_id, string strBindRowID,string[] BindFields)
    {
        BindControl BC = new BindControl();
        try
        {
            if (HttpContext.Current.Request.QueryString["VMODE"] == null)
            {
                if (BC.GetRights(strBindRowID, "edit"))
                {
                    string valuefield = "";
                    string displayfield = "";
                    string strPagesetRowId = "";
                    string strMenuRowId = "";
                    string page_id = "";
                    if (BindFields != null)
                        if (BindFields.Length > 0)
                        {
                            // e.g pageid_control_id
                            //valuefield = BindFields[4].ToString() + "_" + BindFields[0].ToString();
                            //displayfield = BindFields[4].ToString() + "_" + BindFields[1].ToString();
                            valuefield = BindFields[0].ToString();
                            displayfield = BindFields[1].ToString();
                            strPagesetRowId = BindFields[2].ToString();
                            strMenuRowId = BindFields[3].ToString();
                            page_id = BindFields[4].ToString();
                        }
                    //Literal Litcontrol = new Literal();
                    Label Litcontrol = new Label();
                    Litcontrol.ToolTip = "Edit selected record";
                    //Litcontrol.ID = "img_edit_"+displayfield;
                    Litcontrol.Text = "&nbsp;<img id=\"img_edit_" + displayfield + " alt=\"Edit selected record\" src=\"Images/edit_wizard.GIF\" class=\"SearchPopup handCursor\" onclick=\"javascript:ExtendedDropDownAction('" + control_id + "','" + strBindRowID + "','" + strPagesetRowId + "','" + strMenuRowId + "','EDT','" + valuefield + "','" + displayfield + "');\"></img>";
                    htc.Controls.Add(Litcontrol);
                }
            }
        }
        catch(Exception ex)
        {
            LogWriter.WriteLog("Error : AddDDEEditButton : "+ ex.Message);
        }
    }

    public string[] GetBindFields(string strBindRowID,string bindvalue,string bindtext,bool includepageid)
    {
        HDDatabase HDD = new HDDatabase();
        string[] arr = new string[5];
        try
        {
            string sql = "select * From sy_bnd where af_row_id = '" + strBindRowID + "';";
            string strPagesetRowId = HDD.GetColumnValue("select C.af_row_id from sy_bnd A, sy_pg B, sy_pgs C, sy_pgs_mem D where A.bind_table = B.page_table_name and B.page_id = D.page_id and C.af_row_id = D.pageset_id and A.af_row_id = '" + strBindRowID + "'");
            string strMenuRowId = HDD.GetColumnValue("select af_row_id from sy_mnu where pageset_id = '" + strPagesetRowId + "'");
            string page_id = HDD.GetColumnValue("select B.page_id from sy_pgs A, sy_pgs_mem B where A.af_row_id = B.pageset_id and A.af_row_id = '" + strPagesetRowId + "'");
            DataTable dt = HDD.GetDataTable(sql);
            if (dt != null)
                if (dt.Rows.Count > 0)
                {
                    if (includepageid)
                    {
                        arr[0] = page_id +"_"+ bindvalue;
                        arr[1] = page_id + "_" + bindtext;
                    }
                    else
                    {
                        arr[0] = bindvalue;
                        arr[1] = bindtext;
                    }
                }

            

            arr[2] = strPagesetRowId;
            arr[3] = strMenuRowId;
            arr[4] = page_id;
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : GetBindFields : " + ex.Message);
        }
        return arr;
    }

    /// <summary>
    /// This function will return true if MaxBlox Email Compose page can be used
    /// </summary>
    /// <returns></returns>
    private bool UseMaxBloxEmailCompose()//srivatsan
    {
        bool status = false;
        HDDatabase hdd = null;
        try
        {
            hdd = new HDDatabase();
            string sql = "select mem_value1 from sy_acr_mem where af_row_id = '62b95ed0102fc1cb'";
            string result = hdd.GetColumnValue(sql);
            status = result.Trim() != "" ? Convert.ToBoolean(result) : false;
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : UseMaxBloxEmailCompose :" + ex.Message);
        }
        finally
        {
            hdd = null;
        }
        return status;
    }

    private bool CheckForDashboards()
    {
        bool status = false;
        try
        {
            string url = HttpContext.Current.Request.Url.ToString().ToLower();
            if (url.Contains("dashboarddesigner.aspx") || url.Contains("widgetdesigner.aspx"))
            {
                status = true;
            }
        }
        catch(Exception ex)
        {
            LogWriter.WriteLog("Error : CheckForDashboards : "+ ex.Message);
        }
        return status;
    }

    #region Old GetBindFields
    ////public string[] GetBindFields(string strBindRowID)
    ////{
    ////    HDDatabase HDD = new HDDatabase();
    ////    string[] arr = new string[5];
    ////    try
    ////    {
    ////        string sql = "select * From sy_bnd where af_row_id = '"+strBindRowID+"'";
    ////        DataTable dt = HDD.GetDataTable(sql);
    ////        if (dt != null)
    ////            if (dt.Rows.Count > 0)
    ////            {
    ////                arr[0] = dt.Rows[0]["bind_value"].ToString();
    ////                arr[1] = dt.Rows[0]["bind_text"].ToString();
    ////            }

    ////        string strPagesetRowId = HDD.GetColumnValue("select C.pageset_id from sy_bnd A, sy_pg B, sy_pgs C, sy_pgs_mem D where A.bind_table = B.page_table_name and B.page_id = D.page_id and C.af_row_id = D.pageset_id and A.af_row_id = '" + strBindRowID + "'");
    ////        string menu_id = HDD.GetColumnValue("select menu_id from sy_mnu where pageset_id = '" + strPagesetRowId + "'");
    ////        string page_id = HDD.GetColumnValue("select B.page_id from sy_pgs A, sy_pgs_mem B where A.af_row_id = B.pageset_id and A.pageset_id = '" + strPagesetRowId + "'");

    ////        arr[2] = strPagesetRowId;
    ////        arr[3] = menu_id;
    ////        arr[4] = page_id;
    ////    }
    ////    catch(Exception ex)
    ////    {
    ////        LogWriter.WriteLog("Error : GetBindFields : "+ ex.Message);
    ////    }
    ////    return arr;
    ////}
    #endregion
    #region Old Tax Events
    //private void SetEventsForTaxChildFields(DataSet dsTax, string control_id, string page_id, Control cn,int rowcount)
    //{
    //    try
    //    {
    //        if (dsTax != null)
    //            if (dsTax.Tables.Count > 0)
    //            {
    //                if (dsTax.Tables["TaxRecords"] != null)
    //                {
    //                    DataTable dtTaxRecords = dsTax.Tables["TaxRecords"];
    //                    if (dtTaxRecords != null)
    //                        if (dtTaxRecords.Rows.Count > 0)
    //                            foreach (DataRow dr in dtTaxRecords.Rows)
    //                            {
    //                                string childfield = dr["child_field"].ToString().Trim() != "" ? page_id + "_" + dr["child_field"].ToString() : "";
    //                                string taxablefield = dr["taxable_field"].ToString().Trim() != "" ? page_id + "_" + dr["taxable_field"].ToString() : "";
    //                                if (rowcount > 0)
    //                                {
    //                                    childfield = childfield + "_" + rowcount;
    //                                    taxablefield = taxablefield + "_" + rowcount;
    //                                }
    //                                if (childfield.Trim() != "")  // Field that is source for value e.g. amount field
    //                                    if (childfield.ToLower().Trim() == control_id.ToLower().Trim())
    //                                    {
    //                                        AssociateEventToControl(ref cn, "transdoc_refreshTotalFields();");
    //                                    }
    //                                if (taxablefield.Trim() != "")
    //                                    if (taxablefield.ToLower().Trim() == control_id.ToLower().Trim())
    //                                    {
    //                                        AssociateEventToControl(ref cn, "transdoc_refreshTotalFields();");
    //                                    }
    //                            }
    //                }
    //            }
    //    }
    //    catch
    //    {

    //    }
    //}

    ////private void SetEventsForTaxMasterFields(DataSet dsTax, string control_id, string page_id, Control cn)
    ////{
    ////    try
    ////    {
    ////        if (dsTax != null)
    ////            if (dsTax.Tables.Count > 0)
    ////            {
    ////                if (dsTax.Tables["Page"] != null)
    ////                    page_id = dsTax.Tables["Page"].Rows[0]["page_id"].ToString();
    ////                if (dsTax.Tables["GrandTotal"] != null)
    ////                {
    ////                    if (dsTax.Tables["GrandTotal"].Rows.Count > 0)
    ////                    {
    ////                        foreach (DataRow dr in dsTax.Tables["GrandTotal"].Rows)
    ////                        {
    ////                            if (dr["grand_total_attrib_id"].ToString().Trim() != "")
    ////                            {
    ////                                string strid = page_id + "_" + dr["grand_total_attrib_id"].ToString();
    ////                                if (strid.ToLower().Trim() == control_id.ToLower().Trim())
    ////                                {
    ////                                    AssociateEventToControl(ref cn, "transdoc_refreshTotalFields();");
    ////                                }
    ////                            }
    ////                        }
    ////                    }
    ////                }
    ////                if (dsTax.Tables["TaxRecords"] != null)
    ////                {
    ////                    if (dsTax.Tables["TaxRecords"].Rows.Count > 0)
    ////                    {
    ////                        foreach (DataRow drr in dsTax.Tables["TaxRecords"].Rows)
    ////                        {
    ////                            if (drr["percentage_field"].ToString().Trim() != "")
    ////                            {
    ////                                string id = page_id + "_" + drr["percentage_field"].ToString();
    ////                                if (id.ToLower().Trim() == control_id.ToLower().Trim())
    ////                                {
    ////                                    AssociateEventToControl(ref cn, "transdoc_refreshTotalFields();");
    ////                                }
    ////                            }

    ////                            if (drr["master_field"].ToString().Trim() != "")
    ////                            {
    ////                                string id = page_id + "_" + drr["master_field"].ToString();
    ////                                if (id.ToLower().Trim() == control_id.ToLower().Trim())
    ////                                {
    ////                                    AssociateEventToControl(ref cn, "transdoc_refreshTotalFields();");
    ////                                }
    ////                            }
    ////                        }

    ////                    }
    ////                }
    ////            }


    ////    }
    ////    catch
    ////    {

    ////    }
    ////}
    ////private void AssociateEventToControl(ref Control cn, string eventname)
    ////{
    ////    try
    ////    {
    ////        if (cn is TextBox)
    ////        {
    ////            TextBox txt = (TextBox)cn;
    ////            if(!CheckIfAttributeExists(txt.Attributes,eventname))
    ////                setAttribute(txt.Attributes, "onchange","javascript:" + eventname + "");
    ////            // txt.Attributes.Add("onchange", "javascript:" + eventname + "");
    ////        }
    ////        else if (cn is DropDownList)
    ////        {
    ////            DropDownList dd = (DropDownList)cn;
    ////            if (!CheckIfAttributeExists(dd.Attributes, eventname))
    ////            setAttribute(dd.Attributes, "onchange", "javascript:" + eventname + "");
    ////            //dd.Attributes.Add("onchange", "javascript:" + eventname + "");
    ////        }
    ////        else if (cn is CheckBox)
    ////        {
    ////            CheckBox chk = (CheckBox)cn;
    ////            if (!CheckIfAttributeExists(chk.Attributes, eventname))
    ////            setAttribute(chk.Attributes,"onclick","javascript:" + eventname + "");
    ////            //chk.InputAttributes.Add("onclick", "javascript:" + eventname + "");
    ////        }

    ////    }

    ////    catch
    ////    {
    ////    }

    ////}
    ////private bool CheckIfAttributeExists(AttributeCollection attr,string strkey)
    ////{
    ////    bool status = false;
    ////    try
    ////    {
    ////        if (attr != null)
    ////        {
    ////            if(attr.Count>0)
    ////                foreach (string keys in attr.Keys)
    ////                {
    ////                    if(attr[keys].ToLower().Contains(strkey.ToLower()))
    ////                    {
    ////                        status = true;
    ////                    }
    ////                }
    ////        }

    ////    }
    ////    catch
    ////    {

    ////    }
    ////    return status;
    ////}

    ////public void setAttribute(AttributeCollection ac, string attrName, string attrValue)//by sanal on Oct 30, 2009
    ////{
    ////    try
    ////    {
    ////        string temp = "";
    ////        foreach (string keys in ac.Keys)
    ////        {
    ////            if (keys == attrName)
    ////            {
    ////                temp = ac[keys];
    ////                ac.Remove(attrName);
    ////                break;
    ////            }
    ////        }
    ////        if (temp.IndexOf("javascript:") > -1)
    ////        {
    ////            temp += attrValue;
    ////            temp = "javascript:" + temp.Replace("javascript:", "");
    ////        }
    ////        else
    ////            temp += attrValue;
    ////        ac.Add(attrName, temp);
    ////        //code to enhance attribute handling
    ////    }
    ////    catch (Exception e)
    ////    {

    ////    }
    ////}
    #endregion

}
